SF.net SVN: geany:[5586] trunk

colombanw at users.sourceforge.net colombanw at xxxxx
Thu Mar 10 22:27:04 UTC 2011


Revision: 5586
          http://geany.svn.sourceforge.net/geany/?rev=5586&view=rev
Author:   colombanw
Date:     2011-03-10 22:27:04 +0000 (Thu, 10 Mar 2011)

Log Message:
-----------
Prefer prepend elements to lists rather than append them

This is for better performances since appending to a list means walking
it to find the last element to append to. When the list ordering
matters, simply reverse the list after prepengins.

Modified Paths:
--------------
    trunk/ChangeLog
    trunk/plugins/filebrowser.c
    trunk/src/editor.c
    trunk/src/plugins.c
    trunk/src/symbols.c
    trunk/src/tools.c
    trunk/src/utils.c

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2011-03-10 16:05:29 UTC (rev 5585)
+++ trunk/ChangeLog	2011-03-10 22:27:04 UTC (rev 5586)
@@ -3,6 +3,10 @@
  * src/toolbar.c:
    Correctly expand the menubar if the toolbar is appended to it but
    not visible (closes #3204955).
+ * plugins/filebrowser.c, src/editor.c, src/plugins.c, src/symbols.c,
+   src/tools.c, src/utils.c:
+   Prefer prepend elements to lists rather than append them, for better
+   performances.
 
 
 2011-03-08  Enrico Tröger  <enrico(dot)troeger(at)uvena(dot)de>

Modified: trunk/plugins/filebrowser.c
===================================================================
--- trunk/plugins/filebrowser.c	2011-03-10 16:05:29 UTC (rev 5585)
+++ trunk/plugins/filebrowser.c	2011-03-10 22:27:04 UTC (rev 5586)
@@ -492,8 +492,9 @@
 		GtkTreePath *treepath = item->data;
 		gchar *fname = get_tree_path_filename(treepath);
 
-		files = g_slist_append(files, fname);
+		files = g_slist_prepend(files, fname);
 	}
+	files = g_slist_reverse(files);
 	document_open_files(files, FALSE, NULL, NULL);
 	doc = document_get_current();
 	if (doc != NULL && ! do_not_focus)

Modified: trunk/src/editor.c
===================================================================
--- trunk/src/editor.c	2011-03-10 16:05:29 UTC (rev 5585)
+++ trunk/src/editor.c	2011-03-10 22:27:04 UTC (rev 5586)
@@ -2538,7 +2538,7 @@
 		if (i++ > 0)
 		{
 			cursor_steps += (nl_count * indent_size);
-			temp_list = g_list_append(temp_list, GINT_TO_POINTER(cursor_steps - old_cursor));
+			temp_list = g_list_prepend(temp_list, GINT_TO_POINTER(cursor_steps - old_cursor));
 		}
 		else
 		{
@@ -2563,6 +2563,7 @@
 	{
 		GList *node;
 
+		temp_list = g_list_reverse(temp_list);
 		foreach_list(node, temp_list)
 			g_queue_push_nth(snippet_offsets, node->data, i++);
 

Modified: trunk/src/plugins.c
===================================================================
--- trunk/src/plugins.c	2011-03-10 16:05:29 UTC (rev 5585)
+++ trunk/src/plugins.c	2011-03-10 22:27:04 UTC (rev 5586)
@@ -608,7 +608,7 @@
 		add_callbacks(plugin, callbacks);
 
 	/* remember which plugins are active */
-	active_plugin_list = g_list_append(active_plugin_list, plugin);
+	active_plugin_list = g_list_prepend(active_plugin_list, plugin);
 
 	geany_debug("Loaded:   %s (%s)", plugin->filename,
 		NVL(plugin->info.name, "<Unknown>"));
@@ -639,7 +639,7 @@
 	{
 		geany_debug("Plugin \"%s\" already loaded.", fname);
 		if (add_to_list)
-			plugin_list = g_list_append(plugin_list, plugin);
+			plugin_list = g_list_prepend(plugin_list, plugin);
 		return plugin;
 	}
 
@@ -727,7 +727,7 @@
 		plugin_init(plugin);
 
 	if (add_to_list)
-		plugin_list = g_list_append(plugin_list, plugin);
+		plugin_list = g_list_prepend(plugin_list, plugin);
 
 	return plugin;
 }
@@ -814,7 +814,7 @@
 		if (NZV(fname) && g_file_test(fname, G_FILE_TEST_EXISTS))
 		{
 			if (plugin_new(fname, TRUE, FALSE) == NULL)
-				failed_plugins_list = g_list_append(failed_plugins_list, g_strdup(fname));
+				failed_plugins_list = g_list_prepend(failed_plugins_list, g_strdup(fname));
 		}
 	}
 }

Modified: trunk/src/symbols.c
===================================================================
--- trunk/src/symbols.c	2011-03-10 16:05:29 UTC (rev 5585)
+++ trunk/src/symbols.c	2011-03-10 22:27:04 UTC (rev 5586)
@@ -494,7 +494,7 @@
 
 		if (tag->type & tag_types)
 		{
-			tag_names = g_list_append(tag_names, tag);
+			tag_names = g_list_prepend(tag_names, tag);
 		}
 	}
 	tag_names = g_list_sort(tag_names, compare_symbol_lines);

Modified: trunk/src/tools.c
===================================================================
--- trunk/src/tools.c	2011-03-10 16:05:29 UTC (rev 5585)
+++ trunk/src/tools.c	2011-03-10 22:27:04 UTC (rev 5586)
@@ -366,11 +366,12 @@
 			/* if the content of the entry is non-empty, add it to the result array */
 			if (text[0] != '\0')
 			{
-				result_list = g_slist_append(result_list, g_strdup(text));
+				result_list = g_slist_prepend(result_list, g_strdup(text));
 				len++;
 			}
 			g_list_free(list);
 		}
+		result_list = g_slist_reverse(result_list);
 		/* create a new null-terminated array but only if there any commands defined */
 		if (len > 0)
 		{

Modified: trunk/src/utils.c
===================================================================
--- trunk/src/utils.c	2011-03-10 16:05:29 UTC (rev 5585)
+++ trunk/src/utils.c	2011-03-10 22:27:04 UTC (rev 5586)
@@ -1469,13 +1469,15 @@
 
 	foreach_dir(filename, dir)
 	{
-		list = g_slist_append(list, full_path ?
+		list = g_slist_prepend(list, full_path ?
 			g_build_path(G_DIR_SEPARATOR_S, path, filename, NULL) : g_strdup(filename));
 	}
 	g_dir_close(dir);
 	/* sorting last is quicker than on insertion */
 	if (sort)
 		list = g_slist_sort(list, (GCompareFunc) utils_str_casecmp);
+	else
+		list = g_slist_reverse(list);
 	return list;
 }
 


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.



More information about the Commits mailing list