forked from AuroraMiddleware/gtk
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
This commit is contained in:
parent
53a00e3cc3
commit
d68bca1771
@ -6110,10 +6110,11 @@ install_list_model_filter (GtkFileChooserDefault *impl)
|
|||||||
|
|
||||||
#define COMPARE_DIRECTORIES \
|
#define COMPARE_DIRECTORIES \
|
||||||
GtkFileChooserDefault *impl = user_data; \
|
GtkFileChooserDefault *impl = user_data; \
|
||||||
|
GtkFileSystemModel *fs_model = GTK_FILE_SYSTEM_MODEL (model); \
|
||||||
gboolean dir_a, dir_b; \
|
gboolean dir_a, dir_b; \
|
||||||
\
|
\
|
||||||
gtk_tree_model_get (model, a, MODEL_COL_IS_FOLDER, &dir_a, -1); \
|
dir_a = g_value_get_boolean (_gtk_file_system_model_get_value (fs_model, a, MODEL_COL_IS_FOLDER)); \
|
||||||
gtk_tree_model_get (model, b, MODEL_COL_IS_FOLDER, &dir_b, -1); \
|
dir_b = g_value_get_boolean (_gtk_file_system_model_get_value (fs_model, b, MODEL_COL_IS_FOLDER)); \
|
||||||
\
|
\
|
||||||
if (dir_a != dir_b) \
|
if (dir_a != dir_b) \
|
||||||
return impl->list_sort_ascending ? (dir_a ? -1 : 1) : (dir_a ? 1 : -1) /* Directories *always* go first */
|
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;
|
COMPARE_DIRECTORIES;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
gchar *key_a, *key_b;
|
const char *key_a, *key_b;
|
||||||
gint result;
|
gint result;
|
||||||
|
|
||||||
gtk_tree_model_get (model, a, MODEL_COL_NAME_COLLATED, &key_a, -1);
|
key_a = g_value_get_string (_gtk_file_system_model_get_value (fs_model, a, MODEL_COL_NAME_COLLATED));
|
||||||
gtk_tree_model_get (model, b, MODEL_COL_NAME_COLLATED, &key_b, -1);
|
key_b = g_value_get_string (_gtk_file_system_model_get_value (fs_model, b, MODEL_COL_NAME_COLLATED));
|
||||||
|
|
||||||
if (key_a && key_b)
|
if (key_a && key_b)
|
||||||
result = strcmp (key_a, key_b);
|
result = strcmp (key_a, key_b);
|
||||||
else if (key_a)
|
else if (key_a)
|
||||||
return 1;
|
result = 1;
|
||||||
else if (key_b)
|
else if (key_b)
|
||||||
return -1;
|
result = -1;
|
||||||
else
|
else
|
||||||
return 0;
|
result = 0;
|
||||||
|
|
||||||
g_free (key_a);
|
|
||||||
g_free (key_b);
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -6162,8 +6160,8 @@ size_sort_func (GtkTreeModel *model,
|
|||||||
{
|
{
|
||||||
gint64 size_a, size_b;
|
gint64 size_a, size_b;
|
||||||
|
|
||||||
gtk_tree_model_get (model, a, MODEL_COL_SIZE, &size_a, -1);
|
size_a = g_value_get_int64 (_gtk_file_system_model_get_value (fs_model, a, MODEL_COL_SIZE));
|
||||||
gtk_tree_model_get (model, b, MODEL_COL_SIZE, &size_b, -1);
|
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);
|
return size_a > size_b ? -1 : (size_a == size_b ? 0 : 1);
|
||||||
}
|
}
|
||||||
@ -6181,8 +6179,8 @@ mtime_sort_func (GtkTreeModel *model,
|
|||||||
{
|
{
|
||||||
glong ta, tb;
|
glong ta, tb;
|
||||||
|
|
||||||
gtk_tree_model_get (model, a, MODEL_COL_MTIME, &ta, -1);
|
ta = g_value_get_long (_gtk_file_system_model_get_value (fs_model, a, MODEL_COL_MTIME));
|
||||||
gtk_tree_model_get (model, b, MODEL_COL_MTIME, &tb, -1);
|
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);
|
return ta > tb ? -1 : (ta == tb ? 0 : 1);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user