libnm: use nm_utils_named_values_from_str_dict()
Make use of NMUtilsNamedValue in nm_utils_format_variant_attributes(). This avoids creating a GList and sorting it. Also, reuse nm_utils_named_values_from_str_dict() in nm_setting_bond_get_option().
This commit is contained in:
@@ -159,9 +159,7 @@ nm_setting_bond_get_option (NMSettingBond *setting,
|
||||
const char **out_value)
|
||||
{
|
||||
NMSettingBondPrivate *priv;
|
||||
guint i, len;
|
||||
GHashTableIter iter;
|
||||
const char *key, *value;
|
||||
guint len;
|
||||
|
||||
g_return_val_if_fail (NM_IS_SETTING_BOND (setting), FALSE);
|
||||
|
||||
@@ -171,23 +169,8 @@ nm_setting_bond_get_option (NMSettingBond *setting,
|
||||
if (idx >= len)
|
||||
return FALSE;
|
||||
|
||||
if (!G_UNLIKELY (priv->options_idx_cache)) {
|
||||
NMUtilsNamedValue *options;
|
||||
|
||||
i = 0;
|
||||
options = g_new (NMUtilsNamedValue, len);
|
||||
g_hash_table_iter_init (&iter, priv->options);
|
||||
while (g_hash_table_iter_next (&iter, (gpointer *) &key, (gpointer *) &value)) {
|
||||
options[i].name = key;
|
||||
options[i].value_str = value;
|
||||
i++;
|
||||
}
|
||||
nm_assert (i == len);
|
||||
|
||||
g_qsort_with_data (options, len, sizeof (options[0]),
|
||||
nm_utils_named_entry_cmp_with_data, NULL);
|
||||
priv->options_idx_cache = options;
|
||||
}
|
||||
if (!G_UNLIKELY (priv->options_idx_cache))
|
||||
priv->options_idx_cache = nm_utils_named_values_from_str_dict (priv->options, NULL);
|
||||
|
||||
NM_SET_OUT (out_name, priv->options_idx_cache[idx].name);
|
||||
NM_SET_OUT (out_value, priv->options_idx_cache[idx].value_str);
|
||||
|
@@ -5531,8 +5531,8 @@ nm_utils_format_variant_attributes (GHashTable *attributes,
|
||||
const char *name, *value;
|
||||
char *escaped;
|
||||
char buf[64];
|
||||
gs_free_list GList *keys = NULL;
|
||||
GList *iter;
|
||||
gs_free NMUtilsNamedValue *values = NULL;
|
||||
guint i, len;
|
||||
|
||||
g_return_val_if_fail (attr_separator, NULL);
|
||||
g_return_val_if_fail (key_value_separator, NULL);
|
||||
@@ -5540,12 +5540,13 @@ nm_utils_format_variant_attributes (GHashTable *attributes,
|
||||
if (!attributes || !g_hash_table_size (attributes))
|
||||
return NULL;
|
||||
|
||||
keys = g_list_sort (g_hash_table_get_keys (attributes), (GCompareFunc) g_strcmp0);
|
||||
values = nm_utils_named_values_from_str_dict (attributes, &len);
|
||||
|
||||
str = g_string_new ("");
|
||||
|
||||
for (iter = keys; iter; iter = g_list_next (iter)) {
|
||||
name = iter->data;
|
||||
variant = g_hash_table_lookup (attributes, name);
|
||||
for (i = 0; i < len; i++) {
|
||||
name = values[i].name;
|
||||
variant = (GVariant *) values[i].value_ptr;
|
||||
value = NULL;
|
||||
|
||||
if (g_variant_is_of_type (variant, G_VARIANT_TYPE_UINT32))
|
||||
|
Reference in New Issue
Block a user