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.
This commit is contained in:
Timm Bäder 2020-12-31 14:48:31 +01:00
parent 105e44beb5
commit fe441c8ca5

View File

@ -477,9 +477,7 @@ g_io_modules_scan_all_in_directory_with_scope (const char *dirname,
filename = g_build_filename (dirname, "giomodule.cache", NULL); filename = g_build_filename (dirname, "giomodule.cache", NULL);
cache = g_hash_table_new_full (g_str_hash, g_str_equal, cache = NULL;
g_free, (GDestroyNotify)g_strfreev);
cache_time = 0; cache_time = 0;
if (g_stat (filename, &statbuf) == 0 && if (g_stat (filename, &statbuf) == 0 &&
g_file_get_contents (filename, &data, NULL, NULL)) 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)) while (g_ascii_isspace (*colon))
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); extension_points = g_strsplit (colon, ",", -1);
g_hash_table_insert (cache, file, extension_points); 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; GIOExtensionPoint *extension_point;
GIOModule *module; GIOModule *module;
gchar *path; gchar *path;
char **extension_points; char **extension_points = NULL;
int i; int i;
path = g_build_filename (dirname, name, NULL); path = g_build_filename (dirname, name, NULL);
module = g_io_module_new (path); 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 && if (extension_points != NULL &&
g_stat (path, &statbuf) == 0 && g_stat (path, &statbuf) == 0 &&
statbuf.st_ctime <= cache_time) 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_dir_close (dir);
g_hash_table_destroy (cache); if (cache)
g_hash_table_destroy (cache);
g_free (filename); g_free (filename);
} }