From 3c7c0af1c9deba908a9802c433b2776feb243978 Mon Sep 17 00:00:00 2001 From: Allison Ryan Lortie Date: Thu, 28 Apr 2016 09:29:41 +0200 Subject: [PATCH] GResources: use g_hash_table_get_keys_as_array() Replace the hand-written equivalent of this with the call to the GHashTable built-in version to save a few lines of code. The GResource code was written a couple of years before this function existed. Similarly, replace a set-mode usage of g_hash_table_insert() with a call to g_hash_table_add(). https://bugzilla.gnome.org/show_bug.cgi?id=765668 --- gio/gresource.c | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/gio/gresource.c b/gio/gresource.c index 2a10664fe..043153cdf 100644 --- a/gio/gresource.c +++ b/gio/gresource.c @@ -810,7 +810,7 @@ g_resources_enumerate_children (const gchar *path, hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); for (i = 0; children[i] != NULL; i++) - g_hash_table_insert (hash, children[i], children[i]); + g_hash_table_add (hash, children[i]); g_free (children); } } @@ -826,18 +826,8 @@ g_resources_enumerate_children (const gchar *path, } else { - GHashTableIter iter; - const char *key; - guint n_children; - n_children = g_hash_table_size (hash); - children = g_new (char *, n_children + 1); - i = 0; - - g_hash_table_iter_init (&iter, hash); - while (g_hash_table_iter_next (&iter, (gpointer *)&key, NULL)) - children[i++] = g_strdup (key); - children[i++] = NULL; - + children = (gchar **) g_hash_table_get_keys_as_array (hash, NULL); + g_hash_table_steal_all (hash); g_hash_table_destroy (hash); return children;