diff options
author | Thomas Haller <thaller@redhat.com> | 2020-02-20 15:11:20 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2020-02-21 15:59:44 +0100 |
commit | c8d043dd9463c9fb9688c86209dc7b9a46d2430b (patch) | |
tree | 56d63e06c04ad546a9f204c309a70c366a418c02 | |
parent | f13c7e3bbd87492446ab53c925c3d4a887b7f27b (diff) | |
download | NetworkManager-c8d043dd9463c9fb9688c86209dc7b9a46d2430b.tar.gz |
core: avoid duplicate lookup in nm_utils_strdict_to_variant()
Collect the full list of key and values, while sorting the key.
This way, we don't need to lookup the values by key later.
-rw-r--r-- | src/nm-core-utils.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/nm-core-utils.c b/src/nm-core-utils.c index 1ff0764777..a5275963c4 100644 --- a/src/nm-core-utils.c +++ b/src/nm-core-utils.c @@ -4055,18 +4055,18 @@ GVariant * nm_utils_strdict_to_variant (GHashTable *options) { GVariantBuilder builder; - gs_free const char **keys = NULL; + gs_free NMUtilsNamedValue *values = NULL; guint i; - guint nkeys; + guint n; - keys = nm_utils_strdict_get_keys (options, TRUE, &nkeys); + values = nm_utils_named_values_from_str_dict (options, &n); g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}")); - for (i = 0; i < nkeys; i++) { + for (i = 0; i < n; i++) { g_variant_builder_add (&builder, "{sv}", - keys[i], - g_variant_new_string (g_hash_table_lookup (options, keys[i]))); + values[i].name, + g_variant_new_string (values[i].value_str)); } return g_variant_builder_end (&builder); } |