[glib/wip/baedert/gparam: 6/6] giomodule: Don't allocate GHashTable for no entries
- From: Timm Bäder <baedert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/wip/baedert/gparam: 6/6] giomodule: Don't allocate GHashTable for no entries
- Date: Thu, 31 Dec 2020 13:58:55 +0000 (UTC)
commit fe441c8ca5a2ba92a17dc7d6cc408480a63f5681
Author: Timm Bäder <mail baedert org>
Date: Thu Dec 31 14:48:31 2020 +0100
giomodule: Don't allocate GHashTable for no entries
This seems to happen in 3 out of 4 cases when calling gtk_init(), so
avoid allocating the GHashTable in that case.
gio/giomodule.c | 17 +++++++++++------
1 file changed, 11 insertions(+), 6 deletions(-)
---
diff --git a/gio/giomodule.c b/gio/giomodule.c
index e27f1ab76..f20b64875 100644
--- a/gio/giomodule.c
+++ b/gio/giomodule.c
@@ -477,9 +477,7 @@ g_io_modules_scan_all_in_directory_with_scope (const char *dirname,
filename = g_build_filename (dirname, "giomodule.cache", NULL);
- cache = g_hash_table_new_full (g_str_hash, g_str_equal,
- g_free, (GDestroyNotify)g_strfreev);
-
+ cache = NULL;
cache_time = 0;
if (g_stat (filename, &statbuf) == 0 &&
g_file_get_contents (filename, &data, NULL, NULL))
@@ -523,6 +521,10 @@ g_io_modules_scan_all_in_directory_with_scope (const char *dirname,
while (g_ascii_isspace (*colon))
colon++;
+ if (G_UNLIKELY (!cache))
+ cache = g_hash_table_new_full (g_str_hash, g_str_equal,
+ g_free, (GDestroyNotify)g_strfreev);
+
extension_points = g_strsplit (colon, ",", -1);
g_hash_table_insert (cache, file, extension_points);
}
@@ -536,13 +538,15 @@ g_io_modules_scan_all_in_directory_with_scope (const char *dirname,
GIOExtensionPoint *extension_point;
GIOModule *module;
gchar *path;
- char **extension_points;
+ char **extension_points = NULL;
int i;
path = g_build_filename (dirname, name, NULL);
module = g_io_module_new (path);
- extension_points = g_hash_table_lookup (cache, name);
+ if (cache)
+ extension_points = g_hash_table_lookup (cache, name);
+
if (extension_points != NULL &&
g_stat (path, &statbuf) == 0 &&
statbuf.st_ctime <= cache_time)
@@ -577,7 +581,8 @@ g_io_modules_scan_all_in_directory_with_scope (const char *dirname,
g_dir_close (dir);
- g_hash_table_destroy (cache);
+ if (cache)
+ g_hash_table_destroy (cache);
g_free (filename);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]