[gtk+/gtk-2.90] Use the faster accessor function in the sort functions
- From: Christian Dywan <cdywan src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gtk+/gtk-2.90] Use the faster accessor function in the sort functions
- Date: Fri, 16 Oct 2009 13:59:40 +0000 (UTC)
commit 99a1eebbe6f3772a85c4ca93c225cab88b26aeca
Author: Benjamin Otte <otte gnome org>
Date: Wed Jul 1 10:20:04 2009 +0200
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 files changed, 13 insertions(+), 15 deletions(-)
---
diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c
index 9f63aae..7d2c88e 100644
--- a/gtk/gtkfilechooserdefault.c
+++ b/gtk/gtkfilechooserdefault.c
@@ -6106,10 +6106,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 */
@@ -6124,23 +6125,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;
}
@@ -6158,8 +6156,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);
}
@@ -6177,8 +6175,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);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]