summaryrefslogtreecommitdiff
path: root/json-glib/json-gobject.c
diff options
context:
space:
mode:
authorGarrett Regier <garrettregier@gmail.com>2016-10-20 19:44:09 -0700
committerGarrett Regier <garrettregier@gmail.com>2017-06-16 17:16:32 -0700
commitd78ad648942637fb9212d1d93670509d4c7f687b (patch)
treee1e2fe26f63d2d12446fee7aa291f1363e84ec6d /json-glib/json-gobject.c
parent7b3c405df41c0b6f6fe58fdb05c922614f08c4c4 (diff)
downloadjson-glib-d78ad648942637fb9212d1d93670509d4c7f687b.tar.gz
core: Avoid json_object_get_members()
Use JsonObject's private members_ordered GQueue instead. This avoids a g_list_copy(). https://bugzilla.gnome.org/show_bug.cgi?id=773504
Diffstat (limited to 'json-glib/json-gobject.c')
-rw-r--r--json-glib/json-gobject.c21
1 files changed, 8 insertions, 13 deletions
diff --git a/json-glib/json-gobject.c b/json-glib/json-gobject.c
index 923f0e1..abfbb8b 100644
--- a/json-glib/json-gobject.c
+++ b/json-glib/json-gobject.c
@@ -183,7 +183,9 @@ json_gobject_new (GType gtype,
gboolean find_property;
gboolean deserialize_property;
gboolean set_property;
- GList *members, *members_left, *l;
+ GQueue *members;
+ GList *l;
+ GQueue members_left = G_QUEUE_INIT;
guint n_members;
GObjectClass *klass;
GObject *retval;
@@ -193,8 +195,7 @@ json_gobject_new (GType gtype,
klass = g_type_class_ref (gtype);
n_members = json_object_get_size (object);
- members = json_object_get_members (object);
- members_left = NULL;
+ members = json_object_get_members_internal (object);
/* first pass: construct-only properties; here we cannot use Serializable
* because we don't have an instance yet; we use the default implementation
@@ -204,7 +205,7 @@ json_gobject_new (GType gtype,
*/
construct_params = g_array_sized_new (FALSE, FALSE, sizeof (GParameter), n_members);
- for (l = members; l != NULL; l = l->next)
+ for (l = members->head; l != NULL; l = l->next)
{
const gchar *member_name = l->data;
GParamSpec *pspec;
@@ -244,7 +245,7 @@ json_gobject_new (GType gtype,
}
next_member:
- members_left = g_list_prepend (members_left, l->data);
+ g_queue_push_tail (&members_left, l->data);
}
retval = g_object_newv (gtype,
@@ -261,12 +262,6 @@ json_gobject_new (GType gtype,
}
g_array_free (construct_params, TRUE);
- g_list_free (members);
-
- /* we use g_list_prepend() above, but we want to maintain
- * the ordering of json_object_get_members() here
- */
- members = g_list_reverse (members_left);
/* do the Serializable type check once */
if (g_type_is_a (gtype, JSON_TYPE_SERIALIZABLE))
@@ -286,7 +281,7 @@ json_gobject_new (GType gtype,
g_object_freeze_notify (retval);
- for (l = members; l != NULL; l = l->next)
+ for (l = members_left.head; l != NULL; l = l->next)
{
const gchar *member_name = l->data;
GParamSpec *pspec;
@@ -347,7 +342,7 @@ json_gobject_new (GType gtype,
g_value_unset (&value);
}
- g_list_free (members);
+ g_queue_clear (&members_left);
g_object_thaw_notify (retval);