Commit cb06a36a authored by Thomas Haller's avatar Thomas Haller

libnm: avoid deep cloning list of address attribute names for nm_utils_ip_addresses_to_variant()

It's only a temporary list. No need for cloning the names
as well.
parent f299a79d
......@@ -216,6 +216,8 @@ GHashTable *_nm_utils_copy_strdict (GHashTable *strdict);
typedef gpointer (*NMUtilsCopyFunc) (gpointer);
const char **_nm_ip_address_get_attribute_names (const NMIPAddress *addr, gboolean sorted, guint *out_length);
gboolean _nm_ip_route_attribute_validate_all (const NMIPRoute *route);
const char **_nm_ip_route_get_attribute_names (const NMIPRoute *route, gboolean sorted, guint *out_length);
GHashTable *_nm_ip_route_get_attributes_direct (NMIPRoute *route);
......
......@@ -526,6 +526,14 @@ nm_ip_address_set_prefix (NMIPAddress *address,
address->prefix = prefix;
}
const char **
_nm_ip_address_get_attribute_names (const NMIPAddress *address, gboolean sorted, guint *out_length)
{
nm_assert (address);
return nm_utils_strdict_get_keys (address->attributes, sorted, out_length);
}
/**
* nm_ip_address_get_attribute_names:
* @address: the #NMIPAddress
......@@ -541,7 +549,7 @@ nm_ip_address_get_attribute_names (NMIPAddress *address)
g_return_val_if_fail (address, NULL);
names = nm_utils_strdict_get_keys (address->attributes, TRUE, NULL);
names = _nm_ip_address_get_attribute_names (address, TRUE, NULL);
return nm_utils_strv_make_deep_copied_nonnull (names);
}
......@@ -1126,7 +1134,7 @@ _nm_ip_route_get_attributes_direct (NMIPRoute *route)
const char **
_nm_ip_route_get_attribute_names (const NMIPRoute *route, gboolean sorted, guint *out_length)
{
g_return_val_if_fail (route != NULL, NULL);
nm_assert (route);
return nm_utils_strdict_get_keys (route->attributes, sorted, out_length);
}
......
......@@ -1878,7 +1878,7 @@ GVariant *
nm_utils_ip_addresses_to_variant (GPtrArray *addresses)
{
GVariantBuilder builder;
int i;
guint i;
g_variant_builder_init (&builder, G_VARIANT_TYPE ("aa{sv}"));
......@@ -1886,8 +1886,8 @@ nm_utils_ip_addresses_to_variant (GPtrArray *addresses)
for (i = 0; i < addresses->len; i++) {
NMIPAddress *addr = addresses->pdata[i];
GVariantBuilder addr_builder;
char **names;
int n;
gs_free const char **names = NULL;
guint j, len;
g_variant_builder_init (&addr_builder, G_VARIANT_TYPE ("a{sv}"));
g_variant_builder_add (&addr_builder, "{sv}",
......@@ -1897,13 +1897,12 @@ nm_utils_ip_addresses_to_variant (GPtrArray *addresses)
"prefix",
g_variant_new_uint32 (nm_ip_address_get_prefix (addr)));
names = nm_ip_address_get_attribute_names (addr);
for (n = 0; names[n]; n++) {
names = _nm_ip_address_get_attribute_names (addr, TRUE, &len);
for (j = 0; j < len; j++) {
g_variant_builder_add (&addr_builder, "{sv}",
names[n],
nm_ip_address_get_attribute (addr, names[n]));
names[j],
nm_ip_address_get_attribute (addr, names[j]));
}
g_strfreev (names);
g_variant_builder_add (&builder, "a{sv}", &addr_builder);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment