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
This commit is contained in:
Allison Ryan Lortie 2016-04-28 09:29:41 +02:00
parent 05e5da9a83
commit 3c7c0af1c9

View File

@ -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;