mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-05-07 07:18:03 +02:00
libnm: sort entries in nm_setting_bond_get_option()
Since the order was arbitrary before, we can also sort it.
Also rework it, to avoid the creating a temporary GList of keys.
(cherry picked from commit d5b3c6ee53)
This commit is contained in:
parent
ceb9648fbe
commit
bc34ed6382
1 changed files with 19 additions and 11 deletions
|
|
@ -158,26 +158,34 @@ nm_setting_bond_get_option (NMSettingBond *setting,
|
||||||
const char **out_value)
|
const char **out_value)
|
||||||
{
|
{
|
||||||
NMSettingBondPrivate *priv;
|
NMSettingBondPrivate *priv;
|
||||||
GList *keys;
|
guint i, len;
|
||||||
const char *_key = NULL, *_value = NULL;
|
gs_free NMUtilsNamedValue *options = NULL;
|
||||||
|
GHashTableIter iter;
|
||||||
|
const char *key, *value;
|
||||||
|
|
||||||
g_return_val_if_fail (NM_IS_SETTING_BOND (setting), FALSE);
|
g_return_val_if_fail (NM_IS_SETTING_BOND (setting), FALSE);
|
||||||
|
|
||||||
priv = NM_SETTING_BOND_GET_PRIVATE (setting);
|
priv = NM_SETTING_BOND_GET_PRIVATE (setting);
|
||||||
|
|
||||||
if (idx >= nm_setting_bond_get_num_options (setting))
|
len = g_hash_table_size (priv->options);
|
||||||
|
if (idx >= len)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
keys = g_hash_table_get_keys (priv->options);
|
i = 0;
|
||||||
_key = g_list_nth_data (keys, idx);
|
options = g_new (NMUtilsNamedValue, len);
|
||||||
_value = g_hash_table_lookup (priv->options, _key);
|
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);
|
||||||
|
|
||||||
if (out_name)
|
g_qsort_with_data (options, len, sizeof (options[0]),
|
||||||
*out_name = _key;
|
nm_utils_named_entry_cmp_with_data, NULL);
|
||||||
if (out_value)
|
|
||||||
*out_value = _value;
|
|
||||||
|
|
||||||
g_list_free (keys);
|
NM_SET_OUT (out_name, options[idx].name);
|
||||||
|
NM_SET_OUT (out_value, options[idx].value_str);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue