forked from enlightenment/efl
evas/cserve2: Repack strings index when too fragmented
This commit is contained in:
parent
74d399ab81
commit
877532e000
|
@ -388,5 +388,6 @@ int cserve2_shared_string_add(const char *str);
|
|||
int cserve2_shared_string_ref(int id);
|
||||
void cserve2_shared_string_del(int id);
|
||||
const char *cserve2_shared_string_get(int id);
|
||||
int cserve2_shared_strings_repack(Shared_Array_Repack_Skip_Cb skip, Eina_Compare_Cb cmp);
|
||||
|
||||
#endif /* _EVAS_CSERVE2_H */
|
||||
|
|
|
@ -318,8 +318,8 @@ static Eina_Bool
|
|||
_repack_skip_cb(Shared_Array *sa EINA_UNUSED, const void *elem,
|
||||
void *user_data EINA_UNUSED)
|
||||
{
|
||||
const File_Data *fd = elem;
|
||||
return (!fd->refcount);
|
||||
const Shm_Object *obj = elem;
|
||||
return (!obj->refcount);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -411,6 +411,9 @@ skip_images:
|
|||
}
|
||||
skip_fonts:
|
||||
|
||||
if (cserve2_shared_strings_repack(_repack_skip_cb, _shm_object_id_cmp_cb) == 1)
|
||||
updated = EINA_TRUE;
|
||||
|
||||
if (updated)
|
||||
{
|
||||
// TODO: Update strings table generation_id?
|
||||
|
|
|
@ -896,6 +896,8 @@ cserve2_shared_mempool_generation_id_set(Shared_Mempool *sm, int generation_id)
|
|||
|
||||
// Shared strings
|
||||
|
||||
static int _shared_strings_unref_items = 0;
|
||||
|
||||
const char *
|
||||
cserve2_shared_strings_table_name_get()
|
||||
{
|
||||
|
@ -957,7 +959,12 @@ new_entry:
|
|||
int
|
||||
cserve2_shared_string_ref(int id)
|
||||
{
|
||||
Index_Entry *ie;
|
||||
if (id <= 0) return 0;
|
||||
ie = _shared_index_entry_get_by_id(_string_mempool->index, id);
|
||||
if (!ie) return 0;
|
||||
if (!ie->refcount)
|
||||
_string_mempool--;
|
||||
return cserve2_shared_mempool_buffer_ref(_string_mempool, id);
|
||||
}
|
||||
|
||||
|
@ -975,6 +982,7 @@ cserve2_shared_string_del(int id)
|
|||
CRIT("Invalid free");
|
||||
}
|
||||
}
|
||||
_shared_strings_unref_items++;
|
||||
}
|
||||
|
||||
const char *
|
||||
|
@ -984,6 +992,35 @@ cserve2_shared_string_get(int id)
|
|||
return cserve2_shared_mempool_buffer_get(_string_mempool, id);
|
||||
}
|
||||
|
||||
int
|
||||
cserve2_shared_strings_repack(Shared_Array_Repack_Skip_Cb skip,
|
||||
Eina_Compare_Cb cmp)
|
||||
{
|
||||
int count;
|
||||
|
||||
if (!_string_mempool->index) return -1;
|
||||
count = _string_mempool->index->lastid;
|
||||
if (!count) return -1;
|
||||
if (_shared_strings_unref_items * 100 / count >= 25
|
||||
&& _shared_strings_unref_items > 100)
|
||||
{
|
||||
Shared_Array *sa;
|
||||
int genid;
|
||||
|
||||
genid = _string_mempool->index->sa->header->generation_id + 1;
|
||||
sa = cserve2_shared_array_repack(_string_mempool->index->sa, genid,
|
||||
skip, cmp, NULL);
|
||||
if (!sa) return -1;
|
||||
|
||||
cserve2_shared_array_del(_string_mempool->index->sa);
|
||||
_string_mempool->index->sa = sa;
|
||||
_shared_strings_unref_items = 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Init/destroy
|
||||
|
@ -1002,6 +1039,7 @@ cserve2_shared_index_init(void)
|
|||
|
||||
memcpy(faketag, &ifaketag, sizeof(int));
|
||||
cserve2_shared_string_add(faketag);
|
||||
_shared_strings_unref_items = 0;
|
||||
}
|
||||
_instances++;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue