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.
This commit is contained in:
Cedric Bail 2013-12-05 16:25:01 +09:00
parent 3dfc3dcd2c
commit 2e9f96cc24
1 changed files with 7 additions and 2 deletions

View File

@ -64,7 +64,7 @@
#define EINA_HASH_BUCKET_SIZE 8
#define EINA_HASH_SMALL_BUCKET_SIZE 5
#define EINA_HASH_RBTREE_MASK 0xFFFFFF
#define EINA_HASH_RBTREE_MASK 0xFFFF
typedef struct _Eina_Hash_Head Eina_Hash_Head;
typedef struct _Eina_Hash_Element Eina_Hash_Element;
@ -85,6 +85,8 @@ struct _Eina_Hash
int population;
int buckets_power_size;
EINA_MAGIC
};
@ -221,6 +223,7 @@ eina_hash_add_alloc_by_hash(Eina_Hash *hash,
/* Apply eina mask to hash. */
hash_num = key_hash & hash->mask;
key_hash >>= hash->buckets_power_size;
key_hash &= EINA_HASH_RBTREE_MASK;
if (!hash->buckets)
@ -321,7 +324,8 @@ _eina_hash_find_by_hash(const Eina_Hash *hash,
Eina_Hash_Head **hash_head)
{
Eina_Hash_Element *hash_element;
int rb_hash = key_hash & EINA_HASH_RBTREE_MASK;
int rb_hash = (key_hash >> hash->buckets_power_size)
& EINA_HASH_RBTREE_MASK;
key_hash &= hash->mask;
@ -735,6 +739,7 @@ eina_hash_new(Eina_Key_Length key_length_cb,
new->size = 1 << buckets_power_size;
new->mask = new->size - 1;
new->buckets_power_size = buckets_power_size;
return new;