diff options
author | Colin Walters <walters@verbum.org> | 2012-12-13 14:51:32 -0500 |
---|---|---|
committer | Colin Walters <walters@verbum.org> | 2012-12-13 15:12:06 -0500 |
commit | 17053992189a7a4ee2fe8540bb35832a5f695a77 (patch) | |
tree | 68d4c724f857f52fe0ad3128e836ca2c96984e4f | |
parent | c0d3e9641af40124e0b4a2b217c08de48bd2e5c5 (diff) | |
download | libgsystem-17053992189a7a4ee2fe8540bb35832a5f695a77.tar.gz |
fileutils: Use quarks for cached paths
Just faster.
-rw-r--r-- | gsystem-file-utils.c | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/gsystem-file-utils.c b/gsystem-file-utils.c index 1595ee2..546ff99 100644 --- a/gsystem-file-utils.c +++ b/gsystem-file-utils.c @@ -169,13 +169,17 @@ const char * gs_file_get_path_cached (GFile *file) { const char *path; + static GQuark _file_path_quark = 0; - path = g_object_get_data ((GObject*)file, "gs-file-path"); + if (G_UNLIKELY (_file_path_quark) == 0) + _file_path_quark = g_quark_from_static_string ("gsystem-file-path"); + + path = g_object_get_qdata ((GObject*)file, _file_path_quark); if (!path) { path = g_file_get_path (file); g_assert (path != NULL); - g_object_set_data_full ((GObject*)file, "gs-file-path", (char*)path, (GDestroyNotify)g_free); + g_object_set_qdata_full ((GObject*)file, _file_path_quark, (char*)path, (GDestroyNotify)g_free); } return path; } @@ -190,12 +194,16 @@ const char * gs_file_get_basename_cached (GFile *file) { const char *name; + static GQuark _file_name_quark = 0; + + if (G_UNLIKELY (_file_name_quark) == 0) + _file_name_quark = g_quark_from_static_string ("gsystem-file-name"); - name = g_object_get_data ((GObject*)file, "gs-file-name"); + name = g_object_get_qdata ((GObject*)file, _file_name_quark); if (!name) { name = g_file_get_basename (file); - g_object_set_data_full ((GObject*)file, "gs-file-name", (char*)name, (GDestroyNotify)g_free); + g_object_set_qdata_full ((GObject*)file, _file_name_quark, (char*)name, (GDestroyNotify)g_free); } return name; } |