Bug 385893 - List and Table getSelectionIndex methods are not very efficient
Summary: List and Table getSelectionIndex methods are not very efficient
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 4.2   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 4.5 M2   Edit
Assignee: Sravan Kumar Lakkimsetti CLA
QA Contact:
URL:
Whiteboard:
Keywords: performance
Depends on:
Blocks:
 
Reported: 2012-07-24 16:49 EDT by Carolyn MacLeod CLA
Modified: 2014-09-16 07:08 EDT (History)
3 users (show)

See Also:
arunkumar.thondapu: review+


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Carolyn MacLeod CLA 2012-07-24 16:49:36 EDT
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;
}
Comment 1 Carolyn MacLeod CLA 2012-07-26 11:30:56 EDT
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.
Comment 2 Sravan Kumar Lakkimsetti CLA 2014-09-16 07:08:39 EDT
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