[PATCH] Don't install exp. callbacks on multiple selections



When you select multiple (all) files in a directory, nautilus installs
expensive callbacks on each file in the selection (mainly the slow mime
sniffer). Basically you don't need to do it at all because the
availability of the attributes needed to lauch a file are ensured when
activating. But you get better response time on activating if you sniff
the attributes ahead of time, so this patch only installs them when a
single item is selected.
Open a directory with > 1000 files, select all and watch the CPU and I/O
burst. There's a (not so) subtle feedback loop in there too: As the
attributes are progressively sniffed, it is determined that the
selection has changed (because one of the selected files changed) and
the selection gets iterated over again and again.

Martin

? mkinstalldirs
Index: src/file-manager/fm-directory-view.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/file-manager/fm-directory-view.c,v
retrieving revision 1.637
diff -u -p -w -r1.637 fm-directory-view.c
--- src/file-manager/fm-directory-view.c	25 Sep 2004 15:10:24 -0000	1.637
+++ src/file-manager/fm-directory-view.c	1 Oct 2004 14:42:16 -0000
@@ -6256,7 +6256,7 @@ void
 fm_directory_view_notify_selection_changed (FMDirectoryView *view)
 {
 	NautilusFile *file;
-	GList *selection, *p;
+	GList *selection;
 	
 	g_return_if_fail (FM_IS_DIRECTORY_VIEW (view));
 
@@ -6283,9 +6283,13 @@ fm_directory_view_notify_selection_chang
 		/* Schedule an update of menu item states to match selection */
 		schedule_update_menus (view);
 
+		/* If there's exactly one item selected we sniff the slower attributes needed
+		 * to activate a file ahead of time to improve interactive response.
+		 */
 		selection = fm_directory_view_get_selection (view);
-		for (p = selection; p != NULL; p = p->next) {
-			file = p->data;
+
+		if (eel_g_list_exactly_one_item (selection)) {
+			file = NAUTILUS_FILE (selection->data);
 			
 			if (nautilus_file_needs_slow_mime_type (file)) {
 				nautilus_file_call_when_ready
@@ -6301,6 +6305,7 @@ fm_directory_view_notify_selection_chang
 				 NULL, 
 				 NULL);
 		}
+
 		nautilus_file_list_free (selection);
 	}
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]