[Xfce4-commits] <thunar:master> Some optimizations.
Nick Schermer
noreply at xfce.org
Sat Oct 13 16:12:39 CEST 2012
Updating branch refs/heads/master
to 6899eff311c42bff7f2a2e59b07f85b815f8d335 (commit)
from 61c59cd2eda6a9b6c3e1cdd5c942742c1e25d197 (commit)
commit 6899eff311c42bff7f2a2e59b07f85b815f8d335
Author: Nick Schermer <nick at xfce.org>
Date: Sat Oct 13 15:14:28 2012 +0200
Some optimizations.
The file type was called too often and relativly slow in gio,
so cache the value when the file is loaded.
Sorting by filename is also not required anymore and much slower
then the collation method.
thunar/thunar-file.c | 39 +++++++++++++++------------------------
thunar/thunar-file.h | 10 +++++-----
thunar/thunar-list-model.c | 38 ++++----------------------------------
3 files changed, 24 insertions(+), 63 deletions(-)
diff --git a/thunar/thunar-file.c b/thunar/thunar-file.c
index 26ee766..04f00e7 100644
--- a/thunar/thunar-file.c
+++ b/thunar/thunar-file.c
@@ -142,6 +142,7 @@ struct _ThunarFile
/*< private >*/
GFileInfo *info;
+ GFileType kind;
GFile *gfile;
gchar *custom_icon_name;
gchar *display_name;
@@ -692,6 +693,9 @@ thunar_file_info_clear (ThunarFile *file)
file->info = NULL;
}
+ /* unset */
+ file->kind = G_FILE_TYPE_UNKNOWN;
+
/* free the custom icon name */
g_free (file->custom_icon_name);
file->custom_icon_name = NULL;
@@ -740,7 +744,10 @@ thunar_file_info_reload (ThunarFile *file,
if (G_LIKELY (file->info != NULL))
{
- if (g_file_info_get_file_type (file->info) == G_FILE_TYPE_MOUNTABLE)
+ /* this is requesed so often, cache it */
+ file->kind = g_file_info_get_file_type (file->info);
+
+ if (file->kind == G_FILE_TYPE_MOUNTABLE)
{
target_uri = g_file_info_get_attribute_string (file->info, G_FILE_ATTRIBUTE_STANDARD_TARGET_URI);
file->is_mounted = (target_uri != NULL) && !g_file_info_get_attribute_boolean (file->info, G_FILE_ATTRIBUTE_MOUNTABLE_CAN_MOUNT);
@@ -2174,11 +2181,7 @@ GFileType
thunar_file_get_kind (const ThunarFile *file)
{
_thunar_return_val_if_fail (THUNAR_IS_FILE (file), G_FILE_TYPE_UNKNOWN);
-
- if (file->info == NULL)
- return G_FILE_TYPE_UNKNOWN;
-
- return g_file_info_get_file_type (file->info);
+ return file->kind;
}
@@ -2298,11 +2301,7 @@ gboolean
thunar_file_is_directory (const ThunarFile *file)
{
_thunar_return_val_if_fail (THUNAR_IS_FILE (file), FALSE);
-
- if (file->info == NULL)
- return FALSE;
-
- return thunar_file_get_kind (file) == G_FILE_TYPE_DIRECTORY;
+ return file->kind == G_FILE_TYPE_DIRECTORY;
}
@@ -2319,11 +2318,7 @@ gboolean
thunar_file_is_shortcut (const ThunarFile *file)
{
_thunar_return_val_if_fail (THUNAR_IS_FILE (file), FALSE);
-
- if (file->info == NULL)
- return FALSE;
-
- return thunar_file_get_kind (file) == G_FILE_TYPE_SHORTCUT;
+ return file->kind == G_FILE_TYPE_SHORTCUT;
}
@@ -2340,11 +2335,7 @@ gboolean
thunar_file_is_mountable (const ThunarFile *file)
{
_thunar_return_val_if_fail (THUNAR_IS_FILE (file), FALSE);
-
- if (file->info == NULL)
- return FALSE;
-
- return thunar_file_get_kind (file) == G_FILE_TYPE_MOUNTABLE;
+ return file->kind == G_FILE_TYPE_MOUNTABLE;
}
@@ -2610,7 +2601,7 @@ gboolean
thunar_file_is_regular (const ThunarFile *file)
{
_thunar_return_val_if_fail (THUNAR_IS_FILE (file), FALSE);
- return thunar_file_get_kind (file) == G_FILE_TYPE_REGULAR;
+ return file->kind == G_FILE_TYPE_REGULAR;
}
@@ -2660,8 +2651,8 @@ thunar_file_is_desktop_file (const ThunarFile *file,
return FALSE;
/* only allow regular files with a .desktop extension */
- if (!g_str_has_suffix (thunar_file_get_basename (file), ".desktop")
- || g_file_info_get_file_type (file->info) != G_FILE_TYPE_REGULAR)
+ if (!g_str_has_suffix (file->basename, ".desktop")
+ || file->kind != G_FILE_TYPE_REGULAR)
return FALSE;
/* don't check more if not needed */
diff --git a/thunar/thunar-file.h b/thunar/thunar-file.h
index 8ed87d0..564b781 100644
--- a/thunar/thunar-file.h
+++ b/thunar/thunar-file.h
@@ -176,16 +176,16 @@ const gchar *thunar_file_get_basename (const ThunarFile *file
gboolean thunar_file_is_symlink (const ThunarFile *file);
guint64 thunar_file_get_size (const ThunarFile *file);
GAppInfo *thunar_file_get_default_handler (const ThunarFile *file);
-GFileType thunar_file_get_kind (const ThunarFile *file);
+GFileType thunar_file_get_kind (const ThunarFile *file) G_GNUC_PURE;
GFile *thunar_file_get_target_location (const ThunarFile *file);
ThunarFileMode thunar_file_get_mode (const ThunarFile *file);
gboolean thunar_file_get_free_space (const ThunarFile *file,
guint64 *free_space_return);
gboolean thunar_file_is_mounted (const ThunarFile *file);
gboolean thunar_file_exists (const ThunarFile *file);
-gboolean thunar_file_is_directory (const ThunarFile *file);
-gboolean thunar_file_is_shortcut (const ThunarFile *file);
-gboolean thunar_file_is_mountable (const ThunarFile *file);
+gboolean thunar_file_is_directory (const ThunarFile *file) G_GNUC_PURE;
+gboolean thunar_file_is_shortcut (const ThunarFile *file) G_GNUC_PURE;
+gboolean thunar_file_is_mountable (const ThunarFile *file) G_GNUC_PURE;
gboolean thunar_file_is_local (const ThunarFile *file);
gboolean thunar_file_is_parent (const ThunarFile *file,
const ThunarFile *child);
@@ -197,7 +197,7 @@ gboolean thunar_file_is_executable (const ThunarFile *file
gboolean thunar_file_is_writable (const ThunarFile *file);
gboolean thunar_file_is_hidden (const ThunarFile *file);
gboolean thunar_file_is_home (const ThunarFile *file);
-gboolean thunar_file_is_regular (const ThunarFile *file);
+gboolean thunar_file_is_regular (const ThunarFile *file) G_GNUC_PURE;
gboolean thunar_file_is_trashed (const ThunarFile *file);
gboolean thunar_file_is_desktop_file (const ThunarFile *file,
gboolean *is_secure);
diff --git a/thunar/thunar-list-model.c b/thunar/thunar-list-model.c
index c2e4f34..d6c6e19 100644
--- a/thunar/thunar-list-model.c
+++ b/thunar/thunar-list-model.c
@@ -164,9 +164,6 @@ static gint sort_by_date_accessed (const ThunarF
static gint sort_by_date_modified (const ThunarFile *a,
const ThunarFile *b,
gboolean case_sensitive);
-static gint sort_by_file_name (const ThunarFile *a,
- const ThunarFile *b,
- gboolean case_sensitive);
static gint sort_by_group (const ThunarFile *a,
const ThunarFile *b,
gboolean case_sensitive);
@@ -878,7 +875,7 @@ thunar_list_model_get_sort_column_id (GtkTreeSortable *sortable,
*sort_column_id = THUNAR_COLUMN_MIME_TYPE;
else if (store->sort_func == sort_by_name)
*sort_column_id = THUNAR_COLUMN_NAME;
- else if (store->sort_func == sort_by_file_name)
+ else if (store->sort_func == sort_by_name)
*sort_column_id = THUNAR_COLUMN_FILE_NAME;
else if (store->sort_func == sort_by_permissions)
*sort_column_id = THUNAR_COLUMN_PERMISSIONS;
@@ -937,6 +934,7 @@ thunar_list_model_set_sort_column_id (GtkTreeSortable *sortable,
store->sort_func = sort_by_mime_type;
break;
+ case THUNAR_COLUMN_FILE_NAME:
case THUNAR_COLUMN_NAME:
store->sort_func = sort_by_name;
break;
@@ -957,10 +955,6 @@ thunar_list_model_set_sort_column_id (GtkTreeSortable *sortable,
store->sort_func = sort_by_type;
break;
- case THUNAR_COLUMN_FILE_NAME:
- store->sort_func = sort_by_file_name;
- break;
-
default:
_thunar_assert_not_reached ();
}
@@ -1019,11 +1013,8 @@ thunar_list_model_cmp (ThunarListModel *store,
{
isdir_a = thunar_file_is_directory (a);
isdir_b = thunar_file_is_directory (b);
-
- if (isdir_a && !isdir_b)
- return -1;
- else if (!isdir_a && isdir_b)
- return 1;
+ if (isdir_a != isdir_b)
+ return isdir_a ? -1 : 1;
}
return (*store->sort_func) (a, b, store->sort_case_sensitive) * store->sort_sign;
@@ -1411,27 +1402,6 @@ sort_by_date_modified (const ThunarFile *a,
static gint
-sort_by_file_name (const ThunarFile *a,
- const ThunarFile *b,
- gboolean case_sensitive)
-{
- const gchar *a_name = thunar_file_get_display_name (a);
- const gchar *b_name = thunar_file_get_display_name (b);
-
- if (a_name == NULL)
- a_name = "";
- if (b_name == NULL)
- b_name = "";
-
- if (!case_sensitive)
- return strcasecmp (a_name, b_name);
- else
- return strcmp (a_name, b_name);
-}
-
-
-
-static gint
sort_by_group (const ThunarFile *a,
const ThunarFile *b,
gboolean case_sensitive)
More information about the Xfce4-commits
mailing list