diff options
author | Francisco Redondo Marchena <francisco.marchena@codethink.co.uk> | 2012-08-07 11:39:39 +0100 |
---|---|---|
committer | Jannis Pohlmann <jannis.pohlmann@codethink.co.uk> | 2012-08-07 13:28:00 +0100 |
commit | 67d85d78e5cb4e7a21b352903d00ea407ad7763d (patch) | |
tree | a46f9ead0dbab0155243726bc25d90bc09e050d7 /node-startup-controller | |
parent | ed137c3d30e6374bafb293a26a591a1618f6431a (diff) | |
download | node-startup-controller-67d85d78e5cb4e7a21b352903d00ea407ad7763d.tar.gz |
Simplify g_variant_lookup_value_with_int_key
An implementation custom-tailored towards "{ias}" dictionaries is
sufficient for us.
Diffstat (limited to 'node-startup-controller')
-rw-r--r-- | node-startup-controller/glib-extensions.c | 52 |
1 files changed, 14 insertions, 38 deletions
diff --git a/node-startup-controller/glib-extensions.c b/node-startup-controller/glib-extensions.c index d3f161f..a9cd676 100644 --- a/node-startup-controller/glib-extensions.c +++ b/node-startup-controller/glib-extensions.c @@ -23,53 +23,29 @@ g_variant_lookup_value_with_int_key (GVariant *dictionary, const GVariantType *expected_type) { GVariantIter iter; - GVariant *entry; - GVariant *entry_key; - GVariant *tmp; - GVariant *value; - gboolean matches; + GVariant *value = NULL; + gint32 current_key; - g_return_val_if_fail (g_variant_is_of_type (dictionary, G_VARIANT_TYPE ("a{i*}")), - NULL); - g_variant_iter_init (&iter, dictionary); - - while ((entry = g_variant_iter_next_value (&iter))) - { - entry_key = g_variant_get_child_value (entry, 0); - matches = (g_variant_get_int32(entry_key) == key); - g_variant_unref (entry_key); - - if (matches) - break; - - g_variant_unref (entry); - } - - if (entry == NULL) + g_return_val_if_fail (dictionary != NULL, NULL); + g_return_val_if_fail (expected_type != NULL, NULL); + + if (!g_variant_is_of_type (dictionary, G_VARIANT_TYPE ("a{ias}"))) return NULL; - value = g_variant_get_child_value (entry, 1); - g_variant_unref (entry); - - if (g_variant_is_of_type (value, G_VARIANT_TYPE_VARIANT)) + g_variant_iter_init (&iter, dictionary); + while (g_variant_iter_loop (&iter, "{i@as}", ¤t_key, &value)) { - tmp = g_variant_get_variant (value); - g_variant_unref (value); - - if (expected_type && !g_variant_is_of_type (tmp, expected_type)) + if (current_key == key) { - g_variant_unref (tmp); - tmp = NULL; + if (value != NULL && g_variant_is_of_type (value, expected_type)) + return value; + else + return NULL; } - - value = tmp; } - g_return_val_if_fail (expected_type == NULL || value == NULL || - g_variant_is_of_type (value, expected_type), NULL); - - return value; + return NULL; } |