Community
Participate
Working Groups
Currently, GTK List.getSelectionIndex() and Table.getSelectionIndex() use g_list_nth_data to loop through the glist (to find the first selected index, and to free the remaining paths after the selected item is found). They should be using g_list_next, which is far more efficient because it doesn't loop through every element to find the nth. Here is a quick hack of what the List method should probably look like. Also check getSelectionIndices() and all senders of gtk_tree_selection_get_selected_rows to see where else next should be used instead of nth. Bench results with a large list. public int getSelectionIndex () { checkWidget(); int /*long*/ selection = OS.gtk_tree_view_get_selection (handle); int /*long*/ list = OS.gtk_tree_selection_get_selected_rows (selection, null); if (list != 0) { int /*long*/ indices = OS.gtk_tree_path_get_indices (OS.g_list_data(list)); int [] index = new int [1]; if (indices != 0) { OS.memmove (index, indices, 4); } int /*long*/ temp = list; while (temp != 0) { int /*long*/ data = OS.g_list_data(temp); OS.gtk_tree_path_free (data); temp = OS.g_list_next(temp); } // int count = OS.g_list_length (list); // int [] index = new int [1]; // for (int i=0; i<count; i++) { // int /*long*/ data = OS.g_list_nth_data (list, i); // int /*long*/ indices = OS.gtk_tree_path_get_indices (data); // if (indices != 0) { // OS.memmove (index, indices, 4); // for (int j = i; j < count; j++) { // data = OS.g_list_nth_data (list, j); // OS.gtk_tree_path_free (data); // } // break; // } // OS.gtk_tree_path_free (data); // } OS.g_list_free (list); return index [0]; } return -1; }
Actually, should search for all senders of g_list_nth_data and make sure they are not just going through a for i = 0 to length loop.
the code changes have been merged to marter through the commit https://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/?id=e276833c2627745137ae3b73a47f14aad32aa921 The code changes are there in multiple areas. Modified the code to traverse the glist using g_list_next and get the data though g_list->data. instead of using g_list_nth_data. this reduces the complexity of the code and increases the performance