forked from enlightenment/efl
eina: remove the most costly boolean ever.
We did use this 'begin' boolean to make eina_hash always allocate only once per item it push in the hash. This boolean was alone at the end of a structure. It would have costed us 4bytes on 32bits system and 8bytes on 64bits. Removing it make elemines consume 100KB less on 32bits system. We may have a speed impact on hash insertion here, but I don't think we do use eina_hash_add and friends in any hot path, at the moment. If that was the case there would be some way to mitigate this, just not worth it at the moment.
This commit is contained in:
parent
98806b17e2
commit
a11fe38afc
|
@ -92,16 +92,16 @@ struct _Eina_Hash
|
|||
struct _Eina_Hash_Head
|
||||
{
|
||||
EINA_RBTREE;
|
||||
int hash;
|
||||
|
||||
Eina_Rbtree *head;
|
||||
|
||||
int hash;
|
||||
};
|
||||
|
||||
struct _Eina_Hash_Element
|
||||
{
|
||||
EINA_RBTREE;
|
||||
Eina_Hash_Tuple tuple;
|
||||
Eina_Bool begin : 1;
|
||||
};
|
||||
|
||||
struct _Eina_Hash_Foreach_Data
|
||||
|
@ -246,8 +246,7 @@ eina_hash_add_alloc_by_hash(Eina_Hash *hash,
|
|||
if (!hash_head)
|
||||
{
|
||||
/* If not found allocate it and an element. */
|
||||
hash_head = malloc(sizeof(Eina_Hash_Head) + sizeof(Eina_Hash_Element)
|
||||
+ alloc_length);
|
||||
hash_head = malloc(sizeof(Eina_Hash_Head));
|
||||
if (!hash_head)
|
||||
goto on_error;
|
||||
|
||||
|
@ -260,23 +259,15 @@ eina_hash_add_alloc_by_hash(Eina_Hash *hash,
|
|||
EINA_RBTREE_CMP_NODE_CB(
|
||||
_eina_hash_hash_rbtree_cmp_node),
|
||||
NULL);
|
||||
|
||||
new_hash_element = (Eina_Hash_Element *)(hash_head + 1);
|
||||
new_hash_element->begin = EINA_TRUE;
|
||||
}
|
||||
|
||||
/*
|
||||
Alloc a new element
|
||||
(No more lookup as we expect to support more than one item for one key).
|
||||
*/
|
||||
new_hash_element = malloc(sizeof (Eina_Hash_Element) + alloc_length);
|
||||
if (!new_hash_element)
|
||||
{
|
||||
/*
|
||||
Alloc a new element
|
||||
(No more lookup as we expect to support more than one item for one key).
|
||||
*/
|
||||
new_hash_element = malloc(sizeof (Eina_Hash_Element) + alloc_length);
|
||||
if (!new_hash_element)
|
||||
goto on_error;
|
||||
|
||||
new_hash_element->begin = EINA_FALSE;
|
||||
}
|
||||
goto on_error;
|
||||
|
||||
/* Setup the element */
|
||||
new_hash_element->tuple.key_length = key_length;
|
||||
|
@ -403,8 +394,7 @@ _eina_hash_el_free(Eina_Hash_Element *hash_element, Eina_Hash *hash)
|
|||
if (hash->data_free_cb)
|
||||
hash->data_free_cb(hash_element->tuple.data);
|
||||
|
||||
if (hash_element->begin == EINA_FALSE)
|
||||
free(hash_element);
|
||||
free(hash_element);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
Loading…
Reference in New Issue