forked from enlightenment/efl
evas/cserve2: Optimize cserve2_shared_string_del()
eina_hash_del_by_data is very expensive, so let's delete by key since we can get the original data.
This commit is contained in:
parent
e95bd7755e
commit
9d731364c1
|
@ -1588,7 +1588,6 @@ _font_load_request_response(Font_Entry *fe, Slave_Msg_Font_Loaded *msg, int *siz
|
||||||
|
|
||||||
if (fe->base.request) fe->base.request = NULL;
|
if (fe->base.request) fe->base.request = NULL;
|
||||||
|
|
||||||
/* could be a function, but it's too basic and only used here */
|
|
||||||
resp = calloc(1, sizeof(*resp));
|
resp = calloc(1, sizeof(*resp));
|
||||||
resp->base.type = CSERVE2_FONT_LOADED;
|
resp->base.type = CSERVE2_FONT_LOADED;
|
||||||
*size = sizeof(*resp);
|
*size = sizeof(*resp);
|
||||||
|
|
|
@ -765,18 +765,19 @@ cserve2_shared_mempool_buffer_ref(Shared_Mempool *sm, int bufferid)
|
||||||
return ie->id;
|
return ie->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Eina_Bool
|
static const void *
|
||||||
_shared_mempool_buffer_del(Shared_Mempool *sm, int bufferid)
|
_shared_mempool_buffer_del(Shared_Mempool *sm, int bufferid)
|
||||||
{
|
{
|
||||||
Index_Entry *ie;
|
Index_Entry *ie;
|
||||||
|
const char *data;
|
||||||
|
|
||||||
if (!sm || !bufferid) return EINA_FALSE;
|
if (!sm || !bufferid) return NULL;
|
||||||
|
|
||||||
ie = _shared_index_entry_get_by_id(sm->index, bufferid);
|
ie = _shared_index_entry_get_by_id(sm->index, bufferid);
|
||||||
if (!ie || ie->refcount <= 0)
|
if (!ie || ie->refcount <= 0)
|
||||||
{
|
{
|
||||||
CRIT("Tried to delete invalid buffer or with refcount 0");
|
CRIT("Tried to delete invalid buffer or with refcount 0");
|
||||||
return EINA_FALSE;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
ie->refcount--;
|
ie->refcount--;
|
||||||
|
@ -789,10 +790,11 @@ _shared_mempool_buffer_del(Shared_Mempool *sm, int bufferid)
|
||||||
sm->empty_blocks = (Block *) eina_rbtree_inline_insert(
|
sm->empty_blocks = (Block *) eina_rbtree_inline_insert(
|
||||||
EINA_RBTREE_GET(sm->empty_blocks), EINA_RBTREE_GET(newblk),
|
EINA_RBTREE_GET(sm->empty_blocks), EINA_RBTREE_GET(newblk),
|
||||||
EINA_RBTREE_CMP_NODE_CB(_block_rbtree_cmp), NULL);
|
EINA_RBTREE_CMP_NODE_CB(_block_rbtree_cmp), NULL);
|
||||||
return EINA_TRUE;
|
data = sm->ds->data + ie->offset;
|
||||||
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
return EINA_FALSE;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -856,7 +858,7 @@ cserve2_shared_string_add(const char *str)
|
||||||
ie = _shared_index_entry_get_by_id(_string_mempool->index, id);
|
ie = _shared_index_entry_get_by_id(_string_mempool->index, id);
|
||||||
if (!ie || ie->refcount <= 0)
|
if (!ie || ie->refcount <= 0)
|
||||||
{
|
{
|
||||||
CRIT("String found in hash but not in mempool!");
|
ERR("String found in hash but not in mempool!");
|
||||||
eina_hash_del(_string_entries, str, (void *) (intptr_t) id);
|
eina_hash_del(_string_entries, str, (void *) (intptr_t) id);
|
||||||
goto new_entry;
|
goto new_entry;
|
||||||
}
|
}
|
||||||
|
@ -874,9 +876,9 @@ new_entry:
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
eina_hash_add(_string_entries, str, (void *) (intptr_t) ie->id);
|
|
||||||
data = _string_mempool->ds->data + ie->offset;
|
data = _string_mempool->ds->data + ie->offset;
|
||||||
memcpy(data, str, len);
|
memcpy(data, str, len);
|
||||||
|
eina_hash_add(_string_entries, data, (void *) (intptr_t) ie->id);
|
||||||
return ie->id;
|
return ie->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -890,11 +892,16 @@ cserve2_shared_string_ref(int id)
|
||||||
void
|
void
|
||||||
cserve2_shared_string_del(int id)
|
cserve2_shared_string_del(int id)
|
||||||
{
|
{
|
||||||
|
const char *data;
|
||||||
|
|
||||||
if (!id) return;
|
if (!id) return;
|
||||||
if (_shared_mempool_buffer_del(_string_mempool, id))
|
if ((data = _shared_mempool_buffer_del(_string_mempool, id)) != NULL)
|
||||||
{
|
{
|
||||||
if (!eina_hash_del_by_data(_string_entries, (void *) (intptr_t) id))
|
if (!eina_hash_del_by_key(_string_entries, data))
|
||||||
CRIT("Invalid free");
|
{
|
||||||
|
if (!eina_hash_del_by_data(_string_entries, (void *) (intptr_t) id))
|
||||||
|
CRIT("Invalid free");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue