From 3c7185e8806575f948fc4acca2f48443a1173f45 Mon Sep 17 00:00:00 2001 From: Cedric Bail Date: Wed, 4 Dec 2013 17:24:30 +0900 Subject: [PATCH] Revert "eina: check if the complete hash match before checking if the key match during children walk." This reverts commit 295babadb1675d1160b18c639dd6dcbe20b02cfb. The implementation of that said optimization is actually wrong. --- src/lib/eina/eina_hash.c | 31 +++++++++---------------------- 1 file changed, 9 insertions(+), 22 deletions(-) diff --git a/src/lib/eina/eina_hash.c b/src/lib/eina/eina_hash.c index 0989f68..dab865e 100644 --- a/src/lib/eina/eina_hash.c +++ b/src/lib/eina/eina_hash.c @@ -101,7 +101,6 @@ struct _Eina_Hash_Element { EINA_RBTREE; Eina_Hash_Tuple tuple; - int hash; }; struct _Eina_Hash_Foreach_Data @@ -172,21 +171,18 @@ _eina_hash_hash_rbtree_cmp_node(const Eina_Hash_Head *left, static inline int _eina_hash_key_rbtree_cmp_key_data(const Eina_Hash_Element *hash_element, - const Eina_Hash_Element *tuple, + const Eina_Hash_Tuple *tuple, EINA_UNUSED unsigned int key_length, Eina_Key_Cmp cmp) { int result; - result = hash_element->hash - tuple->hash; - if (!result) - result = cmp(hash_element->tuple.key, - hash_element->tuple.key_length, - tuple->tuple.key, - tuple->tuple.key_length); + result = cmp(hash_element->tuple.key, + hash_element->tuple.key_length, + tuple->key, + tuple->key_length); - if (result == 0 && tuple->tuple.data && - tuple->tuple.data != hash_element->tuple.data) + if (result == 0 && tuple->data && tuple->data != hash_element->tuple.data) return 1; return result; @@ -199,10 +195,8 @@ _eina_hash_key_rbtree_cmp_node(const Eina_Hash_Element *left, { int result; - result = left->hash - right->hash; - if (result == 0) - result = cmp(left->tuple.key, left->tuple.key_length, - right->tuple.key, right->tuple.key_length); + result = cmp(left->tuple.key, left->tuple.key_length, + right->tuple.key, right->tuple.key_length); if (result < 0) return EINA_RBTREE_LEFT; @@ -218,7 +212,6 @@ eina_hash_add_alloc_by_hash(Eina_Hash *hash, { Eina_Hash_Element *new_hash_element = NULL; Eina_Hash_Head *hash_head; - int original_key; int hash_num; EINA_SAFETY_ON_NULL_RETURN_VAL(hash, EINA_FALSE); @@ -227,7 +220,6 @@ eina_hash_add_alloc_by_hash(Eina_Hash *hash, EINA_MAGIC_CHECK_HASH(hash); /* Apply eina mask to hash. */ - original_key = key_hash; hash_num = key_hash & hash->mask; key_hash &= EINA_HASH_RBTREE_MASK; @@ -276,7 +268,6 @@ eina_hash_add_alloc_by_hash(Eina_Hash *hash, /* Setup the element */ new_hash_element->tuple.key_length = key_length; new_hash_element->tuple.data = (void *)data; - new_hash_element->hash = original_key; if (alloc_length > 0) { new_hash_element->tuple.key = (char *)(new_hash_element + 1); @@ -330,10 +321,8 @@ _eina_hash_find_by_hash(const Eina_Hash *hash, Eina_Hash_Head **hash_head) { Eina_Hash_Element *hash_element; - Eina_Hash_Element tmp; int rb_hash = key_hash & EINA_HASH_RBTREE_MASK; - tmp.hash = key_hash; key_hash &= hash->mask; if (!hash->buckets) @@ -348,11 +337,9 @@ _eina_hash_find_by_hash(const Eina_Hash *hash, if (!*hash_head) return NULL; - tmp.tuple = *tuple; - hash_element = (Eina_Hash_Element *) eina_rbtree_inline_lookup((*hash_head)->head, - &tmp, 0, + tuple, 0, EINA_RBTREE_CMP_KEY_CB( _eina_hash_key_rbtree_cmp_key_data), (const void *)hash->key_cmp_cb); -- 2.7.4