From d68bca17711eb2fe7bdb05943bcd2125873d5b94 Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Wed, 1 Jul 2009 10:20:04 +0200 Subject: [PATCH] Use the faster accessor function in the sort functions Use the faster _gtk_file_system_model_get_value() function instead of gtk_tree_model_get() inside the sort functions. This gives a significant speed-up when sorting large lists. In a test case with 40.000 files, the sorting time went from ~5 seconds to less than 0.5 seconds for my test case. There is 2 significant problems with gtk_tree_model_get() that cause this: 1) The value is copied, which takes quite a bit of time for strings. ~25% of excessive time or ~1 second in my test 2) The tree model functions need to lookup the interface vfunc. And gtk_tree_model_get() doesn't do that only once, but multiple times (verifying column id, getting the actual value, ...) ~75% of excessive time or ~3 seconds in my test --- gtk/gtkfilechooserdefault.c | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c index 02a9ffc12c..e5f36b7f8b 100644 --- a/gtk/gtkfilechooserdefault.c +++ b/gtk/gtkfilechooserdefault.c @@ -6110,10 +6110,11 @@ install_list_model_filter (GtkFileChooserDefault *impl) #define COMPARE_DIRECTORIES \ GtkFileChooserDefault *impl = user_data; \ + GtkFileSystemModel *fs_model = GTK_FILE_SYSTEM_MODEL (model); \ gboolean dir_a, dir_b; \ \ - gtk_tree_model_get (model, a, MODEL_COL_IS_FOLDER, &dir_a, -1); \ - gtk_tree_model_get (model, b, MODEL_COL_IS_FOLDER, &dir_b, -1); \ + dir_a = g_value_get_boolean (_gtk_file_system_model_get_value (fs_model, a, MODEL_COL_IS_FOLDER)); \ + dir_b = g_value_get_boolean (_gtk_file_system_model_get_value (fs_model, b, MODEL_COL_IS_FOLDER)); \ \ if (dir_a != dir_b) \ return impl->list_sort_ascending ? (dir_a ? -1 : 1) : (dir_a ? 1 : -1) /* Directories *always* go first */ @@ -6128,23 +6129,20 @@ name_sort_func (GtkTreeModel *model, COMPARE_DIRECTORIES; else { - gchar *key_a, *key_b; + const char *key_a, *key_b; gint result; - gtk_tree_model_get (model, a, MODEL_COL_NAME_COLLATED, &key_a, -1); - gtk_tree_model_get (model, b, MODEL_COL_NAME_COLLATED, &key_b, -1); + key_a = g_value_get_string (_gtk_file_system_model_get_value (fs_model, a, MODEL_COL_NAME_COLLATED)); + key_b = g_value_get_string (_gtk_file_system_model_get_value (fs_model, b, MODEL_COL_NAME_COLLATED)); if (key_a && key_b) result = strcmp (key_a, key_b); else if (key_a) - return 1; + result = 1; else if (key_b) - return -1; + result = -1; else - return 0; - - g_free (key_a); - g_free (key_b); + result = 0; return result; } @@ -6162,8 +6160,8 @@ size_sort_func (GtkTreeModel *model, { gint64 size_a, size_b; - gtk_tree_model_get (model, a, MODEL_COL_SIZE, &size_a, -1); - gtk_tree_model_get (model, b, MODEL_COL_SIZE, &size_b, -1); + size_a = g_value_get_int64 (_gtk_file_system_model_get_value (fs_model, a, MODEL_COL_SIZE)); + size_b = g_value_get_int64 (_gtk_file_system_model_get_value (fs_model, b, MODEL_COL_SIZE)); return size_a > size_b ? -1 : (size_a == size_b ? 0 : 1); } @@ -6181,8 +6179,8 @@ mtime_sort_func (GtkTreeModel *model, { glong ta, tb; - gtk_tree_model_get (model, a, MODEL_COL_MTIME, &ta, -1); - gtk_tree_model_get (model, b, MODEL_COL_MTIME, &tb, -1); + ta = g_value_get_long (_gtk_file_system_model_get_value (fs_model, a, MODEL_COL_MTIME)); + tb = g_value_get_long (_gtk_file_system_model_get_value (fs_model, b, MODEL_COL_MTIME)); return ta > tb ? -1 : (ta == tb ? 0 : 1); }