commit a7042dfef6c4329776d0523bddb8c8c2288cc92c
parent f2be6f7822c568a4348b4db193058d0f72ac88db
Author: Louis Burda <quent.burda@gmail.com>
Date: Mon, 20 Mar 2023 14:45:09 +0100
Optimize _link_pos
Diffstat:
1 file changed, 10 insertions(+), 8 deletions(-)
diff --git a/src/hashmap.c b/src/hashmap.c
@@ -106,14 +106,14 @@ hashmap_clear(struct hashmap *map)
}
struct hashmap_link **
-hashmap_link_get(struct hashmap *map, const void *key, size_t size)
+hashmap_link_get(struct hashmap *map, const void *key, size_t keysize)
{
struct hashmap_link **iter, *link;
- iter = &map->buckets[hashmap_key_bucket(map, key, size)];
+ iter = &map->buckets[hashmap_key_bucket(map, key, keysize)];
while (*iter != NULL) {
link = *iter;
- if (map->keycmp(link->key, link->keysize, key, size))
+ if (map->keycmp(link->key, link->keysize, key, keysize))
return iter;
iter = &(*iter)->next;
}
@@ -124,12 +124,14 @@ hashmap_link_get(struct hashmap *map, const void *key, size_t size)
struct hashmap_link **
hashmap_link_pos(struct hashmap *map, const void *key, size_t keysize)
{
- struct hashmap_link **iter;
+ struct hashmap_link **iter, *link;
- iter = hashmap_link_get(map, key, keysize);
- if (iter == NULL) {
- iter = &map->buckets[hashmap_key_bucket(map, key, keysize)];
- while (*iter) iter = &((*iter)->next);
+ iter = &map->buckets[hashmap_key_bucket(map, key, keysize)];
+ while (*iter != NULL) {
+ link = *iter;
+ if (map->keycmp(link->key, link->keysize, key, keysize))
+ return iter;
+ iter = &(*iter)->next;
}
return iter;