diff options
author | Cedric Bail <cedric.bail@samsung.com> | 2013-12-04 17:24:30 +0900 |
---|---|---|
committer | Cedric Bail <cedric.bail@samsung.com> | 2013-12-04 18:33:04 +0900 |
commit | 3c7185e8806575f948fc4acca2f48443a1173f45 (patch) | |
tree | de1f4f7f62a4740797722e339d5b64be1355f283 /src/lib/eina | |
parent | 517f339fd0cbcece6c796062290659cf501889be (diff) |
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.
Diffstat (limited to 'src/lib/eina')
-rw-r--r-- | src/lib/eina/eina_hash.c | 31 |
1 files changed, 9 insertions, 22 deletions
diff --git a/src/lib/eina/eina_hash.c b/src/lib/eina/eina_hash.c index 0989f68342..dab865efe6 100644 --- a/src/lib/eina/eina_hash.c +++ b/src/lib/eina/eina_hash.c | |||
@@ -101,7 +101,6 @@ struct _Eina_Hash_Element | |||
101 | { | 101 | { |
102 | EINA_RBTREE; | 102 | EINA_RBTREE; |
103 | Eina_Hash_Tuple tuple; | 103 | Eina_Hash_Tuple tuple; |
104 | int hash; | ||
105 | }; | 104 | }; |
106 | 105 | ||
107 | struct _Eina_Hash_Foreach_Data | 106 | struct _Eina_Hash_Foreach_Data |
@@ -172,21 +171,18 @@ _eina_hash_hash_rbtree_cmp_node(const Eina_Hash_Head *left, | |||
172 | 171 | ||
173 | static inline int | 172 | static inline int |
174 | _eina_hash_key_rbtree_cmp_key_data(const Eina_Hash_Element *hash_element, | 173 | _eina_hash_key_rbtree_cmp_key_data(const Eina_Hash_Element *hash_element, |
175 | const Eina_Hash_Element *tuple, | 174 | const Eina_Hash_Tuple *tuple, |
176 | EINA_UNUSED unsigned int key_length, | 175 | EINA_UNUSED unsigned int key_length, |
177 | Eina_Key_Cmp cmp) | 176 | Eina_Key_Cmp cmp) |
178 | { | 177 | { |
179 | int result; | 178 | int result; |
180 | 179 | ||
181 | result = hash_element->hash - tuple->hash; | 180 | result = cmp(hash_element->tuple.key, |
182 | if (!result) | 181 | hash_element->tuple.key_length, |
183 | result = cmp(hash_element->tuple.key, | 182 | tuple->key, |
184 | hash_element->tuple.key_length, | 183 | tuple->key_length); |
185 | tuple->tuple.key, | ||
186 | tuple->tuple.key_length); | ||
187 | 184 | ||
188 | if (result == 0 && tuple->tuple.data && | 185 | if (result == 0 && tuple->data && tuple->data != hash_element->tuple.data) |
189 | tuple->tuple.data != hash_element->tuple.data) | ||
190 | return 1; | 186 | return 1; |
191 | 187 | ||
192 | return result; | 188 | return result; |
@@ -199,10 +195,8 @@ _eina_hash_key_rbtree_cmp_node(const Eina_Hash_Element *left, | |||
199 | { | 195 | { |
200 | int result; | 196 | int result; |
201 | 197 | ||
202 | result = left->hash - right->hash; | 198 | result = cmp(left->tuple.key, left->tuple.key_length, |
203 | if (result == 0) | 199 | right->tuple.key, right->tuple.key_length); |
204 | result = cmp(left->tuple.key, left->tuple.key_length, | ||
205 | right->tuple.key, right->tuple.key_length); | ||
206 | 200 | ||
207 | if (result < 0) | 201 | if (result < 0) |
208 | return EINA_RBTREE_LEFT; | 202 | return EINA_RBTREE_LEFT; |
@@ -218,7 +212,6 @@ eina_hash_add_alloc_by_hash(Eina_Hash *hash, | |||
218 | { | 212 | { |
219 | Eina_Hash_Element *new_hash_element = NULL; | 213 | Eina_Hash_Element *new_hash_element = NULL; |
220 | Eina_Hash_Head *hash_head; | 214 | Eina_Hash_Head *hash_head; |
221 | int original_key; | ||
222 | int hash_num; | 215 | int hash_num; |
223 | 216 | ||
224 | EINA_SAFETY_ON_NULL_RETURN_VAL(hash, EINA_FALSE); | 217 | EINA_SAFETY_ON_NULL_RETURN_VAL(hash, EINA_FALSE); |
@@ -227,7 +220,6 @@ eina_hash_add_alloc_by_hash(Eina_Hash *hash, | |||
227 | EINA_MAGIC_CHECK_HASH(hash); | 220 | EINA_MAGIC_CHECK_HASH(hash); |
228 | 221 | ||
229 | /* Apply eina mask to hash. */ | 222 | /* Apply eina mask to hash. */ |
230 | original_key = key_hash; | ||
231 | hash_num = key_hash & hash->mask; | 223 | hash_num = key_hash & hash->mask; |
232 | key_hash &= EINA_HASH_RBTREE_MASK; | 224 | key_hash &= EINA_HASH_RBTREE_MASK; |
233 | 225 | ||
@@ -276,7 +268,6 @@ eina_hash_add_alloc_by_hash(Eina_Hash *hash, | |||
276 | /* Setup the element */ | 268 | /* Setup the element */ |
277 | new_hash_element->tuple.key_length = key_length; | 269 | new_hash_element->tuple.key_length = key_length; |
278 | new_hash_element->tuple.data = (void *)data; | 270 | new_hash_element->tuple.data = (void *)data; |
279 | new_hash_element->hash = original_key; | ||
280 | if (alloc_length > 0) | 271 | if (alloc_length > 0) |
281 | { | 272 | { |
282 | new_hash_element->tuple.key = (char *)(new_hash_element + 1); | 273 | new_hash_element->tuple.key = (char *)(new_hash_element + 1); |
@@ -330,10 +321,8 @@ _eina_hash_find_by_hash(const Eina_Hash *hash, | |||
330 | Eina_Hash_Head **hash_head) | 321 | Eina_Hash_Head **hash_head) |
331 | { | 322 | { |
332 | Eina_Hash_Element *hash_element; | 323 | Eina_Hash_Element *hash_element; |
333 | Eina_Hash_Element tmp; | ||
334 | int rb_hash = key_hash & EINA_HASH_RBTREE_MASK; | 324 | int rb_hash = key_hash & EINA_HASH_RBTREE_MASK; |
335 | 325 | ||
336 | tmp.hash = key_hash; | ||
337 | key_hash &= hash->mask; | 326 | key_hash &= hash->mask; |
338 | 327 | ||
339 | if (!hash->buckets) | 328 | if (!hash->buckets) |
@@ -348,11 +337,9 @@ _eina_hash_find_by_hash(const Eina_Hash *hash, | |||
348 | if (!*hash_head) | 337 | if (!*hash_head) |
349 | return NULL; | 338 | return NULL; |
350 | 339 | ||
351 | tmp.tuple = *tuple; | ||
352 | |||
353 | hash_element = (Eina_Hash_Element *) | 340 | hash_element = (Eina_Hash_Element *) |
354 | eina_rbtree_inline_lookup((*hash_head)->head, | 341 | eina_rbtree_inline_lookup((*hash_head)->head, |
355 | &tmp, 0, | 342 | tuple, 0, |
356 | EINA_RBTREE_CMP_KEY_CB( | 343 | EINA_RBTREE_CMP_KEY_CB( |
357 | _eina_hash_key_rbtree_cmp_key_data), | 344 | _eina_hash_key_rbtree_cmp_key_data), |
358 | (const void *)hash->key_cmp_cb); | 345 | (const void *)hash->key_cmp_cb); |