From 84f5af58c23b174cc9708e81ce8ccbfffa6e68eb Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Fri, 30 Oct 2009 10:46:32 +0000 Subject: object: Return values list in insertion order Since we return the member names in insertion order, we should also return the member values in the same order. This also allows us to get rid of the (yucky) internal copies of g_hash_table_get_keys() and g_hash_table_get_values(), since we use the hash table only for storage and lookup purposes. --- json-glib/json-object.c | 55 +++++++------------------------------------------ 1 file changed, 7 insertions(+), 48 deletions(-) (limited to 'json-glib/json-object.c') diff --git a/json-glib/json-object.c b/json-glib/json-object.c index 862cd0e..9a339a1 100644 --- a/json-glib/json-object.c +++ b/json-glib/json-object.c @@ -402,53 +402,6 @@ json_object_set_object_member (JsonObject *object, object_set_member_internal (object, member_name, node); } -/* FIXME: yuck */ -#if GLIB_MAJOR_VERSION == 2 && GLIB_MINOR_VERSION < 14 -static void -get_keys (gpointer key, - gpointer value, - gpointer user_data) -{ - GList **keys = user_data; - - *keys = g_list_prepend (*keys, key); -} - -static void -get_values (gpointer key, - gpointer value, - gpointer user_data) -{ - GList **values = user_data; - - *values = g_list_prepend (*values, value); -} - -static GList * -g_hash_table_get_keys (GHashTable *hash_table) -{ - GList *retval = NULL; - - g_return_val_if_fail (hash_table != NULL, NULL); - - g_hash_table_foreach (hash_table, get_keys, &retval); - - return retval; -} - -static GList * -g_hash_table_get_values (GHashTable *hash_table) -{ - GList *retval = NULL; - - g_return_val_if_fail (hash_table != NULL, NULL); - - g_hash_table_foreach (hash_table, get_values, &retval); - - return retval; -} -#endif /* GLIB_MAJOR_VERSION == 2 && GLIB_MINOR_VERSION < 14 */ - /** * json_object_get_members: * @object: a #JsonObject @@ -487,9 +440,15 @@ json_object_get_members (JsonObject *object) GList * json_object_get_values (JsonObject *object) { + GList *values, *l; + g_return_val_if_fail (object != NULL, NULL); - return g_hash_table_get_values (object->members); + values = NULL; + for (l = object->members_ordered; l != NULL; l = l->next) + values = g_list_prepend (values, g_hash_table_lookup (object->members, l->data)); + + return values; } /** -- cgit v1.2.1