summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2017-06-20 10:29:40 +0200
committerThomas Haller <thaller@redhat.com>2017-07-05 14:22:10 +0200
commit3f76b5b7eb418caaa47897c8b8169877a5fdf757 (patch)
tree6a6538754c3dda4ec44c126ab38970409f6ebd1b
parent489e346e87d8c63e563bda2e001039121b805771 (diff)
downloadNetworkManager-3f76b5b7eb418caaa47897c8b8169877a5fdf757.tar.gz
core: use NM_HASH_COMBINE() function
-rw-r--r--libnm-core/nm-utils.c8
-rw-r--r--src/devices/nm-lldp-listener.c10
-rw-r--r--src/platform/nmp-object.c42
3 files changed, 30 insertions, 30 deletions
diff --git a/libnm-core/nm-utils.c b/libnm-core/nm-utils.c
index c52948bd7b..2958cd90d9 100644
--- a/libnm-core/nm-utils.c
+++ b/libnm-core/nm-utils.c
@@ -4016,16 +4016,16 @@ _nm_utils_strstrdictkey_hash (gconstpointer a)
if (((int) k->type) & ~STRSTRDICTKEY_ALL_SET)
g_return_val_if_reached (0);
- h = (h << 5) + h + k->type;
+ h = NM_HASH_COMBINE (h, k->type);
if (k->type & STRSTRDICTKEY_ALL_SET) {
p = (void *) k->data;
for (; *p != '\0'; p++)
- h = (h << 5) + h + *p;
+ h = NM_HASH_COMBINE (h, *p);
if (k->type == STRSTRDICTKEY_ALL_SET) {
/* the key contains two strings. Continue... */
- h = (h << 5) + h + '\0';
+ h = NM_HASH_COMBINE (h, '\0');
for (p++; *p != '\0'; p++)
- h = (h << 5) + h + *p;
+ h = NM_HASH_COMBINE (h, *p);
}
}
}
diff --git a/src/devices/nm-lldp-listener.c b/src/devices/nm-lldp-listener.c
index bfd631f0fd..8f12fd8595 100644
--- a/src/devices/nm-lldp-listener.c
+++ b/src/devices/nm-lldp-listener.c
@@ -274,12 +274,12 @@ static guint
lldp_neighbor_id_hash (gconstpointer ptr)
{
const LldpNeighbor *neigh = ptr;
- guint hash;
+ guint hash = 23423423u;
- hash = 23423423u + ((guint) (neigh->chassis_id ? g_str_hash (neigh->chassis_id) : 12321u));
- hash = (hash * 33u) + ((guint) (neigh->port_id ? g_str_hash (neigh->port_id) : 34342343u));
- hash = (hash * 33u) + ((guint) neigh->chassis_id_type);
- hash = (hash * 33u) + ((guint) neigh->port_id_type);
+ hash = NM_HASH_COMBINE (hash, neigh->chassis_id ? g_str_hash (neigh->chassis_id) : 12321u);
+ hash = NM_HASH_COMBINE (hash, neigh->port_id ? g_str_hash (neigh->port_id) : 34342343u);
+ hash = NM_HASH_COMBINE (hash, neigh->chassis_id_type);
+ hash = NM_HASH_COMBINE (hash, neigh->port_id_type);
return hash;
}
diff --git a/src/platform/nmp-object.c b/src/platform/nmp-object.c
index 3ea3fbba4f..2d77824bf9 100644
--- a/src/platform/nmp-object.c
+++ b/src/platform/nmp-object.c
@@ -81,7 +81,7 @@ _id_hash_ip6_addr (const struct in6_addr *addr)
int i;
for (i = 0; i < sizeof (*addr); i++)
- hash = (hash * 33) + ((const guint8 *) addr)[i];
+ hash = NM_HASH_COMBINE (hash, ((const guint8 *) addr)[i]);
return hash;
}
@@ -846,39 +846,39 @@ _vt_cmd_plobj_id_hash_##type (const NMPlatformObject *_obj) \
}
_vt_cmd_plobj_id_hash (link, NMPlatformLink, {
hash = (guint) 3982791431u;
- hash = hash + ((guint) obj->ifindex);
+ hash = hash + ((guint) obj->ifindex);
})
_vt_cmd_plobj_id_hash (ip4_address, NMPlatformIP4Address, {
hash = (guint) 3591309853u;
- hash = hash + ((guint) obj->ifindex);
- hash = hash * 33 + ((guint) obj->plen);
- hash = hash * 33 + ((guint) obj->address);
-
+ hash = hash + ((guint) obj->ifindex);
+ hash = NM_HASH_COMBINE (hash, obj->plen);
+ hash = NM_HASH_COMBINE (hash, obj->address);
/* for IPv4 we must also consider the net-part of the peer-address (IFA_ADDRESS) */
- hash = hash * 33 + ((guint) (obj->peer_address & nm_utils_ip4_prefix_to_netmask (obj->plen)));
+ hash = NM_HASH_COMBINE (hash, (obj->peer_address & nm_utils_ip4_prefix_to_netmask (obj->plen)));
})
_vt_cmd_plobj_id_hash (ip6_address, NMPlatformIP6Address, {
hash = (guint) 2907861637u;
- hash = hash + ((guint) obj->ifindex);
+ hash = hash + ((guint) obj->ifindex);
/* for IPv6 addresses, the prefix length is not part of the primary identifier. */
- hash = hash * 33 + _id_hash_ip6_addr (&obj->address);
+ hash = NM_HASH_COMBINE (hash, _id_hash_ip6_addr (&obj->address));
})
_vt_cmd_plobj_id_hash (ip4_route, NMPlatformIP4Route, {
hash = (guint) 2569857221u;
- hash = hash + ((guint) obj->ifindex);
- hash = hash * 33 + ((guint) obj->plen);
- hash = hash * 33 + ((guint) obj->metric);
- hash = hash * 33 + ((guint) nm_utils_ip4_address_clear_host_address (obj->network, obj->plen));
+ hash = hash + ((guint) obj->ifindex);
+ hash = NM_HASH_COMBINE (hash, obj->plen);
+ hash = NM_HASH_COMBINE (hash, obj->metric);
+ hash = NM_HASH_COMBINE (hash, nm_utils_ip4_address_clear_host_address (obj->network, obj->plen));
})
_vt_cmd_plobj_id_hash (ip6_route, NMPlatformIP6Route, {
hash = (guint) 3999787007u;
- hash = hash + ((guint) obj->ifindex);
- hash = hash * 33 + ((guint) obj->plen);
- hash = hash * 33 + ((guint) obj->metric);
- hash = hash * 33 + ({
- struct in6_addr n1;
- _id_hash_ip6_addr (nm_utils_ip6_address_clear_host_address (&n1, &obj->network, obj->plen));
- });
+ hash = hash + ((guint) obj->ifindex);
+ hash = NM_HASH_COMBINE (hash, obj->plen);
+ hash = NM_HASH_COMBINE (hash, obj->metric);
+ hash = NM_HASH_COMBINE (hash,
+ ({
+ struct in6_addr n1;
+ _id_hash_ip6_addr (nm_utils_ip6_address_clear_host_address (&n1, &obj->network, obj->plen));
+ }));
})
gboolean
@@ -989,7 +989,7 @@ nmp_cache_id_hash (const NMPCacheId *id)
n = _nmp_cache_id_size_by_type (id->_id_type);
for (i = 0; i < n; i++)
- hash = ((hash << 5) + hash) + ((char *) id)[i]; /* hash * 33 + c */
+ hash = NM_HASH_COMBINE (hash, ((char *) id)[i]);
return hash;
}