summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2020-11-19 15:35:48 +0100
committerThomas Haller <thaller@redhat.com>2020-11-20 16:59:56 +0100
commitd10d96a45c56fad99cd446d9a3952b6100d46191 (patch)
treec53a77c08fd35a501430645f43ab4b418ae9ebce
parent190eeb5e9f66005b20812995fba752e6877d0b04 (diff)
downloadNetworkManager-d10d96a45c56fad99cd446d9a3952b6100d46191.tar.gz
dns: track NMDnsConfigData as keys of a dictionary
There is unnecessary overhead of tracking a separate key and value in a GHashTable. Use g_hash_table_add().
-rw-r--r--src/dns/nm-dns-manager.c13
-rw-r--r--src/dns/nm-dns-manager.h2
2 files changed, 9 insertions, 6 deletions
diff --git a/src/dns/nm-dns-manager.c b/src/dns/nm-dns-manager.c
index eafdba9e9f..e040221090 100644
--- a/src/dns/nm-dns-manager.c
+++ b/src/dns/nm-dns-manager.c
@@ -1716,7 +1716,7 @@ nm_dns_manager_set_ip_config(NMDnsManager * self,
priv = NM_DNS_MANAGER_GET_PRIVATE(self);
- data = g_hash_table_lookup(priv->configs, GINT_TO_POINTER(ifindex));
+ data = g_hash_table_lookup(priv->configs, &ifindex);
if (!data)
ip_data = NULL;
else
@@ -1732,7 +1732,7 @@ nm_dns_manager_set_ip_config(NMDnsManager * self,
/* deleting a config doesn't invalidate the configs' sort order. */
_ip_config_data_free(ip_data);
if (c_list_is_empty(&data->data_lst_head))
- g_hash_table_remove(priv->configs, GINT_TO_POINTER(ifindex));
+ g_hash_table_remove(priv->configs, &ifindex);
goto changed;
}
@@ -1749,7 +1749,7 @@ nm_dns_manager_set_ip_config(NMDnsManager * self,
.data_lst_head = C_LIST_INIT(data->data_lst_head),
};
_ASSERT_config_data(data);
- g_hash_table_insert(priv->configs, GINT_TO_POINTER(ifindex), data);
+ g_hash_table_add(priv->configs, data);
}
if (!ip_data)
@@ -2402,8 +2402,11 @@ nm_dns_manager_init(NMDnsManager *self)
priv->config = g_object_ref(nm_config_get());
- priv->configs =
- g_hash_table_new_full(nm_direct_hash, NULL, NULL, (GDestroyNotify) _config_data_free);
+ G_STATIC_ASSERT_EXPR(G_STRUCT_OFFSET(NMDnsConfigData, ifindex) == 0);
+ priv->configs = g_hash_table_new_full(nm_pint_hash,
+ nm_pint_equals,
+ (GDestroyNotify) _config_data_free,
+ NULL);
/* Set the initial hash */
compute_hash(self, NULL, NM_DNS_MANAGER_GET_PRIVATE(self)->hash);
diff --git a/src/dns/nm-dns-manager.h b/src/dns/nm-dns-manager.h
index f91d1556bc..dc305a68ba 100644
--- a/src/dns/nm-dns-manager.h
+++ b/src/dns/nm-dns-manager.h
@@ -41,9 +41,9 @@ typedef struct {
} NMDnsIPConfigData;
typedef struct _NMDnsConfigData {
+ int ifindex;
struct _NMDnsManager *self;
CList data_lst_head;
- int ifindex;
} NMDnsConfigData;
#define NM_TYPE_DNS_MANAGER (nm_dns_manager_get_type())