diff options
author | Cedric Bail <cedric.bail@samsung.com> | 2013-12-05 16:25:01 +0900 |
---|---|---|
committer | Cedric Bail <cedric.bail@samsung.com> | 2013-12-05 16:32:02 +0900 |
commit | 2e9f96cc24f99452bdaf2a4592ea881fe259b86a (patch) | |
tree | 940c4ee9bfc88f82fee30bd8690de13e2aa5cc12 /src/lib/eina | |
parent | 3dfc3dcd2c75cb09391d85b70889070b66644935 (diff) |
eina: this is actually a better way of improving Eina_Hash performance.
This reduce the size of the rbtree part dedicated to the hash key match,
but reuse only bit that weren't matched by the bucket.
Diffstat (limited to 'src/lib/eina')
-rw-r--r-- | src/lib/eina/eina_hash.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/lib/eina/eina_hash.c b/src/lib/eina/eina_hash.c index 4b060644af..716a1d89d5 100644 --- a/src/lib/eina/eina_hash.c +++ b/src/lib/eina/eina_hash.c | |||
@@ -64,7 +64,7 @@ | |||
64 | #define EINA_HASH_BUCKET_SIZE 8 | 64 | #define EINA_HASH_BUCKET_SIZE 8 |
65 | #define EINA_HASH_SMALL_BUCKET_SIZE 5 | 65 | #define EINA_HASH_SMALL_BUCKET_SIZE 5 |
66 | 66 | ||
67 | #define EINA_HASH_RBTREE_MASK 0xFFFFFF | 67 | #define EINA_HASH_RBTREE_MASK 0xFFFF |
68 | 68 | ||
69 | typedef struct _Eina_Hash_Head Eina_Hash_Head; | 69 | typedef struct _Eina_Hash_Head Eina_Hash_Head; |
70 | typedef struct _Eina_Hash_Element Eina_Hash_Element; | 70 | typedef struct _Eina_Hash_Element Eina_Hash_Element; |
@@ -85,6 +85,8 @@ struct _Eina_Hash | |||
85 | 85 | ||
86 | int population; | 86 | int population; |
87 | 87 | ||
88 | int buckets_power_size; | ||
89 | |||
88 | EINA_MAGIC | 90 | EINA_MAGIC |
89 | }; | 91 | }; |
90 | 92 | ||
@@ -221,6 +223,7 @@ eina_hash_add_alloc_by_hash(Eina_Hash *hash, | |||
221 | 223 | ||
222 | /* Apply eina mask to hash. */ | 224 | /* Apply eina mask to hash. */ |
223 | hash_num = key_hash & hash->mask; | 225 | hash_num = key_hash & hash->mask; |
226 | key_hash >>= hash->buckets_power_size; | ||
224 | key_hash &= EINA_HASH_RBTREE_MASK; | 227 | key_hash &= EINA_HASH_RBTREE_MASK; |
225 | 228 | ||
226 | if (!hash->buckets) | 229 | if (!hash->buckets) |
@@ -321,7 +324,8 @@ _eina_hash_find_by_hash(const Eina_Hash *hash, | |||
321 | Eina_Hash_Head **hash_head) | 324 | Eina_Hash_Head **hash_head) |
322 | { | 325 | { |
323 | Eina_Hash_Element *hash_element; | 326 | Eina_Hash_Element *hash_element; |
324 | int rb_hash = key_hash & EINA_HASH_RBTREE_MASK; | 327 | int rb_hash = (key_hash >> hash->buckets_power_size) |
328 | & EINA_HASH_RBTREE_MASK; | ||
325 | 329 | ||
326 | key_hash &= hash->mask; | 330 | key_hash &= hash->mask; |
327 | 331 | ||
@@ -735,6 +739,7 @@ eina_hash_new(Eina_Key_Length key_length_cb, | |||
735 | 739 | ||
736 | new->size = 1 << buckets_power_size; | 740 | new->size = 1 << buckets_power_size; |
737 | new->mask = new->size - 1; | 741 | new->mask = new->size - 1; |
742 | new->buckets_power_size = buckets_power_size; | ||
738 | 743 | ||
739 | return new; | 744 | return new; |
740 | 745 | ||