[nautilus] file: use a collation key for comparing directory names
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus] file: use a collation key for comparing directory names
- Date: Mon, 1 Sep 2014 22:36:56 +0000 (UTC)
commit c3807ba49056014c90c36ed317753e1d9b38c6aa
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Mon Sep 1 11:46:00 2014 -0700
file: use a collation key for comparing directory names
Or we'll have to redo utf8 validation/normalization every time we add a
file into the directory, when we sort files that way.
libnautilus-private/nautilus-file-private.h | 1 +
libnautilus-private/nautilus-file.c | 27 +++++++++++----------------
2 files changed, 12 insertions(+), 16 deletions(-)
---
diff --git a/libnautilus-private/nautilus-file-private.h b/libnautilus-private/nautilus-file-private.h
index 1beaa60..47c25df 100644
--- a/libnautilus-private/nautilus-file-private.h
+++ b/libnautilus-private/nautilus-file-private.h
@@ -53,6 +53,7 @@ struct NautilusFileDetails
eel_ref_str display_name;
char *display_name_collation_key;
+ char *directory_name_collation_key;
eel_ref_str edit_name;
goffset size; /* -1 is unknown */
diff --git a/libnautilus-private/nautilus-file.c b/libnautilus-private/nautilus-file.c
index 1c27edd..1052dba 100644
--- a/libnautilus-private/nautilus-file.c
+++ b/libnautilus-private/nautilus-file.c
@@ -504,8 +504,16 @@ void
nautilus_file_set_directory (NautilusFile *file,
NautilusDirectory *directory)
{
+ char *parent_uri;
+
g_clear_object (&file->details->directory);
+ g_free (file->details->directory_name_collation_key);
+
file->details->directory = nautilus_directory_ref (directory);
+
+ parent_uri = nautilus_file_get_parent_uri (file);
+ file->details->directory_name_collation_key = g_utf8_collate_key_for_filename (parent_uri, -1);
+ g_free (parent_uri);
}
static NautilusFile *
@@ -793,6 +801,7 @@ finalize (GObject *object)
eel_ref_str_unref (file->details->name);
eel_ref_str_unref (file->details->display_name);
g_free (file->details->display_name_collation_key);
+ g_free (file->details->directory_name_collation_key);
eel_ref_str_unref (file->details->edit_name);
if (file->details->icon) {
g_object_unref (file->details->icon);
@@ -2888,22 +2897,8 @@ compare_by_display_name (NautilusFile *file_1, NautilusFile *file_2)
static int
compare_by_directory_name (NautilusFile *file_1, NautilusFile *file_2)
{
- char *directory_1, *directory_2;
- int compare;
-
- if (file_1->details->directory == file_2->details->directory) {
- return 0;
- }
-
- directory_1 = nautilus_file_get_parent_uri_for_display (file_1);
- directory_2 = nautilus_file_get_parent_uri_for_display (file_2);
-
- compare = g_utf8_collate (directory_1, directory_2);
-
- g_free (directory_1);
- g_free (directory_2);
-
- return compare;
+ return strcmp (file_1->details->directory_name_collation_key,
+ file_2->details->directory_name_collation_key);
}
static GList *
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]