Kaydet (Commit) 8e79a225 authored tarafından Colomban Wendling's avatar Colomban Wendling

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.

git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@5586 ea778897-0a13-0410-b9d1-a72fbfd435f5
üst 6f481c80
...@@ -3,6 +3,10 @@ ...@@ -3,6 +3,10 @@
* src/toolbar.c: * src/toolbar.c:
Correctly expand the menubar if the toolbar is appended to it but Correctly expand the menubar if the toolbar is appended to it but
not visible (closes #3204955). 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> 2011-03-08 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
......
...@@ -492,8 +492,9 @@ static void open_selected_files(GList *list, gboolean do_not_focus) ...@@ -492,8 +492,9 @@ static void open_selected_files(GList *list, gboolean do_not_focus)
GtkTreePath *treepath = item->data; GtkTreePath *treepath = item->data;
gchar *fname = get_tree_path_filename(treepath); 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); document_open_files(files, FALSE, NULL, NULL);
doc = document_get_current(); doc = document_get_current();
if (doc != NULL && ! do_not_focus) if (doc != NULL && ! do_not_focus)
......
...@@ -2538,7 +2538,7 @@ static gssize snippets_make_replacements(GeanyEditor *editor, GString *pattern, ...@@ -2538,7 +2538,7 @@ static gssize snippets_make_replacements(GeanyEditor *editor, GString *pattern,
if (i++ > 0) if (i++ > 0)
{ {
cursor_steps += (nl_count * indent_size); 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 else
{ {
...@@ -2563,6 +2563,7 @@ static gssize snippets_make_replacements(GeanyEditor *editor, GString *pattern, ...@@ -2563,6 +2563,7 @@ static gssize snippets_make_replacements(GeanyEditor *editor, GString *pattern,
{ {
GList *node; GList *node;
temp_list = g_list_reverse(temp_list);
foreach_list(node, temp_list) foreach_list(node, temp_list)
g_queue_push_nth(snippet_offsets, node->data, i++); g_queue_push_nth(snippet_offsets, node->data, i++);
......
...@@ -608,7 +608,7 @@ plugin_init(Plugin *plugin) ...@@ -608,7 +608,7 @@ plugin_init(Plugin *plugin)
add_callbacks(plugin, callbacks); add_callbacks(plugin, callbacks);
/* remember which plugins are active */ /* 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, geany_debug("Loaded: %s (%s)", plugin->filename,
NVL(plugin->info.name, "<Unknown>")); NVL(plugin->info.name, "<Unknown>"));
...@@ -639,7 +639,7 @@ plugin_new(const gchar *fname, gboolean init_plugin, gboolean add_to_list) ...@@ -639,7 +639,7 @@ plugin_new(const gchar *fname, gboolean init_plugin, gboolean add_to_list)
{ {
geany_debug("Plugin \"%s\" already loaded.", fname); geany_debug("Plugin \"%s\" already loaded.", fname);
if (add_to_list) if (add_to_list)
plugin_list = g_list_append(plugin_list, plugin); plugin_list = g_list_prepend(plugin_list, plugin);
return plugin; return plugin;
} }
...@@ -727,7 +727,7 @@ plugin_new(const gchar *fname, gboolean init_plugin, gboolean add_to_list) ...@@ -727,7 +727,7 @@ plugin_new(const gchar *fname, gboolean init_plugin, gboolean add_to_list)
plugin_init(plugin); plugin_init(plugin);
if (add_to_list) if (add_to_list)
plugin_list = g_list_append(plugin_list, plugin); plugin_list = g_list_prepend(plugin_list, plugin);
return plugin; return plugin;
} }
...@@ -814,7 +814,7 @@ load_active_plugins(void) ...@@ -814,7 +814,7 @@ load_active_plugins(void)
if (NZV(fname) && g_file_test(fname, G_FILE_TEST_EXISTS)) if (NZV(fname) && g_file_test(fname, G_FILE_TEST_EXISTS))
{ {
if (plugin_new(fname, TRUE, FALSE) == NULL) 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));
} }
} }
} }
......
...@@ -494,7 +494,7 @@ static GList *get_tag_list(GeanyDocument *doc, guint tag_types) ...@@ -494,7 +494,7 @@ static GList *get_tag_list(GeanyDocument *doc, guint tag_types)
if (tag->type & tag_types) 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); tag_names = g_list_sort(tag_names, compare_symbol_lines);
......
...@@ -366,11 +366,12 @@ static void cc_show_dialog_custom_commands(void) ...@@ -366,11 +366,12 @@ static void cc_show_dialog_custom_commands(void)
/* if the content of the entry is non-empty, add it to the result array */ /* if the content of the entry is non-empty, add it to the result array */
if (text[0] != '\0') 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++; len++;
} }
g_list_free(list); g_list_free(list);
} }
result_list = g_slist_reverse(result_list);
/* create a new null-terminated array but only if there any commands defined */ /* create a new null-terminated array but only if there any commands defined */
if (len > 0) if (len > 0)
{ {
......
...@@ -1469,13 +1469,15 @@ GSList *utils_get_file_list_full(const gchar *path, gboolean full_path, gboolean ...@@ -1469,13 +1469,15 @@ GSList *utils_get_file_list_full(const gchar *path, gboolean full_path, gboolean
foreach_dir(filename, dir) 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_build_path(G_DIR_SEPARATOR_S, path, filename, NULL) : g_strdup(filename));
} }
g_dir_close(dir); g_dir_close(dir);
/* sorting last is quicker than on insertion */ /* sorting last is quicker than on insertion */
if (sort) if (sort)
list = g_slist_sort(list, (GCompareFunc) utils_str_casecmp); list = g_slist_sort(list, (GCompareFunc) utils_str_casecmp);
else
list = g_slist_reverse(list);
return list; return list;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment