forked from enlightenment/efl
eet: another big boolean removed.
By merging all boolean in their own array I avoid loosing 2.9 bytes on 32bits and 6.9 bytes on 64bits system.
This commit is contained in:
parent
a11fe38afc
commit
fa20ab7269
|
@ -33,13 +33,13 @@ struct _Eet_String
|
||||||
|
|
||||||
int next;
|
int next;
|
||||||
int prev;
|
int prev;
|
||||||
|
|
||||||
unsigned char hash;
|
|
||||||
unsigned char allocated : 1;
|
|
||||||
};
|
};
|
||||||
struct _Eet_Dictionary
|
struct _Eet_Dictionary
|
||||||
{
|
{
|
||||||
Eet_String *all;
|
Eet_String *all;
|
||||||
|
unsigned char *all_hash;
|
||||||
|
unsigned char *all_allocated;
|
||||||
|
|
||||||
Eina_Hash *converts;
|
Eina_Hash *converts;
|
||||||
Eina_Lock mutex;
|
Eina_Lock mutex;
|
||||||
|
|
||||||
|
|
|
@ -36,11 +36,12 @@ eet_dictionary_free(Eet_Dictionary *ed)
|
||||||
eina_lock_free(&ed->mutex);
|
eina_lock_free(&ed->mutex);
|
||||||
|
|
||||||
for (i = 0; i < ed->count; ++i)
|
for (i = 0; i < ed->count; ++i)
|
||||||
if (ed->all[i].allocated)
|
if (ed->all_allocated[i >> 8] & (1 << (i & 0x7)))
|
||||||
eina_stringshare_del(ed->all[i].str);
|
eina_stringshare_del(ed->all[i].str);
|
||||||
|
|
||||||
if (ed->all)
|
free(ed->all);
|
||||||
free(ed->all);
|
free(ed->all_hash);
|
||||||
|
free(ed->all_allocated);
|
||||||
|
|
||||||
if (ed->converts) eina_hash_free(ed->converts);
|
if (ed->converts) eina_hash_free(ed->converts);
|
||||||
|
|
||||||
|
@ -117,14 +118,24 @@ eet_dictionary_string_add(Eet_Dictionary *ed,
|
||||||
if (ed->total == ed->count)
|
if (ed->total == ed->count)
|
||||||
{
|
{
|
||||||
Eet_String *new;
|
Eet_String *new;
|
||||||
|
unsigned char *new_hash;
|
||||||
|
unsigned char *new_allocated;
|
||||||
int total;
|
int total;
|
||||||
|
|
||||||
total = ed->total + 8;
|
total = ed->total + 8;
|
||||||
|
|
||||||
new = realloc(ed->all, total * sizeof(Eet_String));
|
new = realloc(ed->all, total * sizeof(Eet_String));
|
||||||
if (!new) goto on_error;
|
if (!new) goto on_error;
|
||||||
|
|
||||||
ed->all = new;
|
ed->all = new;
|
||||||
|
|
||||||
|
new_hash = realloc(ed->all_hash, total * sizeof (unsigned char));
|
||||||
|
if (!new_hash) goto on_error;
|
||||||
|
ed->all_hash = new_hash;
|
||||||
|
|
||||||
|
new_allocated = realloc(ed->all_allocated, total * sizeof (unsigned char));
|
||||||
|
if (!new_allocated) goto on_error;
|
||||||
|
ed->all_allocated = new_allocated;
|
||||||
|
|
||||||
ed->total = total;
|
ed->total = total;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,9 +144,8 @@ eet_dictionary_string_add(Eet_Dictionary *ed,
|
||||||
|
|
||||||
current = ed->all + ed->count;
|
current = ed->all + ed->count;
|
||||||
|
|
||||||
current->allocated = EINA_TRUE;
|
ed->all_allocated[ed->count >> 8] |= (1 << (ed->count & 0x7));
|
||||||
|
ed->all_hash[ed->count] = hash;
|
||||||
current->hash = hash;
|
|
||||||
|
|
||||||
current->str = str;
|
current->str = str;
|
||||||
current->len = len;
|
current->len = len;
|
||||||
|
@ -209,7 +219,7 @@ eet_dictionary_string_get_hash(const Eet_Dictionary *ed,
|
||||||
eina_lock_take((Eina_Lock*) &ed->mutex);
|
eina_lock_take((Eina_Lock*) &ed->mutex);
|
||||||
|
|
||||||
if (idx < ed->count)
|
if (idx < ed->count)
|
||||||
hash = ed->all[idx].hash;
|
hash = ed->all_hash[idx];
|
||||||
|
|
||||||
eina_lock_release((Eina_Lock*) &ed->mutex);
|
eina_lock_release((Eina_Lock*) &ed->mutex);
|
||||||
|
|
||||||
|
@ -233,10 +243,10 @@ eet_dictionary_string_get_char(const Eet_Dictionary *ed,
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
/* Windows file system could change the mmaped file when replacing a file. So we need to copy all string in memory to avoid bugs. */
|
/* Windows file system could change the mmaped file when replacing a file. So we need to copy all string in memory to avoid bugs. */
|
||||||
if (!ed->all[idx].allocated)
|
if (!(ed->all_allocated[idx >> 8] & (1 << (idx & 0x7))))
|
||||||
{
|
{
|
||||||
ed->all[idx].str = eina_stringshare_add(ed->all[idx].str);
|
ed->all[idx].str = eina_stringshare_add(ed->all[idx].str);
|
||||||
ed->all[idx].allocated = EINA_TRUE;
|
ed->all_allocated[idx >> 8] |= (1 << (idx & 0x7));
|
||||||
}
|
}
|
||||||
#endif /* ifdef _WIN32 */
|
#endif /* ifdef _WIN32 */
|
||||||
s = ed->all[idx].str;
|
s = ed->all[idx].str;
|
||||||
|
@ -500,7 +510,7 @@ eet_dictionary_string_check(Eet_Dictionary *ed,
|
||||||
if (!res)
|
if (!res)
|
||||||
{
|
{
|
||||||
for (i = 0; i < ed->count; ++i)
|
for (i = 0; i < ed->count; ++i)
|
||||||
if ((ed->all[i].allocated) && ed->all[i].str == string)
|
if ((ed->all_allocated[i >> 8] & (1 << (i & 0x7))) && ed->all[i].str == string)
|
||||||
{
|
{
|
||||||
res = 1;
|
res = 1;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -446,7 +446,7 @@ eet_flush2(Eet_File *ef)
|
||||||
{
|
{
|
||||||
int sbuf[EET_FILE2_DICTIONARY_ENTRY_COUNT];
|
int sbuf[EET_FILE2_DICTIONARY_ENTRY_COUNT];
|
||||||
|
|
||||||
sbuf[0] = (int)htonl((unsigned int)ef->ed->all[j].hash);
|
sbuf[0] = (int)htonl((unsigned int)ef->ed->all_hash[j]);
|
||||||
sbuf[1] = (int)htonl((unsigned int)offset);
|
sbuf[1] = (int)htonl((unsigned int)offset);
|
||||||
sbuf[2] = (int)htonl((unsigned int)ef->ed->all[j].len);
|
sbuf[2] = (int)htonl((unsigned int)ef->ed->all[j].len);
|
||||||
sbuf[3] = (int)htonl((unsigned int)ef->ed->all[j].prev);
|
sbuf[3] = (int)htonl((unsigned int)ef->ed->all[j].prev);
|
||||||
|
@ -942,6 +942,14 @@ eet_internal_read2(Eet_File *ef)
|
||||||
if (eet_test_close(!ef->ed->all, ef))
|
if (eet_test_close(!ef->ed->all, ef))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
ef->ed->all_hash = calloc(1, num_dictionary_entries * sizeof (unsigned char));
|
||||||
|
if (eet_test_close(!ef->ed->all_hash, ef))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
ef->ed->all_allocated = calloc(1, (num_dictionary_entries >> 8) * sizeof (unsigned char));
|
||||||
|
if (eet_test_close(!ef->ed->all_allocated, ef))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
ef->ed->count = num_dictionary_entries;
|
ef->ed->count = num_dictionary_entries;
|
||||||
ef->ed->total = num_dictionary_entries;
|
ef->ed->total = num_dictionary_entries;
|
||||||
ef->ed->start = start + bytes_dictionary_entries +
|
ef->ed->start = start + bytes_dictionary_entries +
|
||||||
|
@ -983,7 +991,7 @@ eet_internal_read2(Eet_File *ef)
|
||||||
'\0', ef))
|
'\0', ef))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
ef->ed->all[j].hash = hash;
|
ef->ed->all_hash[j] = hash;
|
||||||
if (ef->ed->all[j].prev == -1)
|
if (ef->ed->all[j].prev == -1)
|
||||||
ef->ed->hash[hash] = j;
|
ef->ed->hash[hash] = j;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue