Mercurial > geeqie.yaz
changeset 833:1d6fedb891dc
optimized vflist_setup_iter_recursive
author | nadvornik |
---|---|
date | Sat, 14 Jun 2008 17:14:28 +0000 |
parents | a14d7da2736d |
children | e5cb9f4389f4 |
files | src/view_file_list.c |
diffstat | 1 files changed, 28 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/view_file_list.c Sat Jun 14 12:43:39 2008 +0000 +++ b/src/view_file_list.c Sat Jun 14 17:14:28 2008 +0000 @@ -769,6 +769,8 @@ GList *work; GtkTreeIter iter; gint valid; + gint num_ordered = 0; + gint num_prepended = 0; valid = gtk_tree_model_iter_children(GTK_TREE_MODEL(store), &iter, parent_iter); @@ -786,6 +788,7 @@ if (valid) { + num_ordered++; gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, FILE_COLUMN_POINTER, &old_fd, FILE_COLUMN_VERSION, &old_version, @@ -821,7 +824,12 @@ } else { - gtk_tree_store_append(store, &new, parent_iter); + /* + here should be used gtk_tree_store_append, but this function seems to be O(n) + and it seems to be much faster to add new entries to the beginning and reorder later + */ + num_prepended++; + gtk_tree_store_prepend(store, &new, parent_iter); } vflist_setup_iter(vf, store, &new, file_data_ref(fd)); @@ -866,6 +874,25 @@ valid = gtk_tree_store_remove(store, &iter); } + + /* move the prepended entries to the correct position */ + if (num_prepended) + { + gint i; + gint num_total = num_prepended + num_ordered; + gint *new_order = g_malloc(num_total * sizeof(gint)); + + for (i = 0; i < num_total; i++) + { + if (i < num_ordered) + new_order[i] = num_prepended + i; + else + new_order[i] = num_total - 1 - i; + } + gtk_tree_store_reorder(store, parent_iter, new_order); + + g_free(new_order); + } } void vflist_sort_set(ViewFile *vf, SortType type, gint ascend)