From e0807ce79796a20f5b88dea9a3e748e28b0c9497 Mon Sep 17 00:00:00 2001 From: Cedric Bail Date: Tue, 17 Oct 2017 16:11:25 -0700 Subject: [PATCH] eina: fix eina_hash_stringshared_new to actually compute the hash on the pointer. Before this patch, the key would always be zero and the hash would solely rely on the rbtree to be efficient. This improve the situation by using the pointer as the key during hash computation. --- src/lib/eina/eina_hash.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/lib/eina/eina_hash.c b/src/lib/eina/eina_hash.c index e4d8662eb7..c24bc9e677 100644 --- a/src/lib/eina/eina_hash.c +++ b/src/lib/eina/eina_hash.c @@ -490,6 +490,12 @@ _eina_hash_del_by_key(Eina_Hash *hash, const void *key, const void *data) return _eina_hash_del_by_key_hash(hash, key, key_length, key_hash, data); } +static int +_eina_stringshared_hash(const void *key, int key_length EINA_UNUSED) +{ + return eina_hash_superfast(&key, sizeof (void*)); +} + static unsigned int _eina_string_key_length(const char *key) { @@ -846,7 +852,7 @@ eina_hash_stringshared_new(Eina_Free_Cb data_free_cb) { return eina_hash_new(NULL, EINA_KEY_CMP(_eina_stringshared_key_cmp), - EINA_KEY_HASH(eina_hash_superfast), + EINA_KEY_HASH(_eina_stringshared_hash), data_free_cb, EINA_HASH_BUCKET_SIZE); }