diff --git a/src/lib/eet/Eet_private.h b/src/lib/eet/Eet_private.h index e4cb713f99..87d66c4eaf 100644 --- a/src/lib/eet/Eet_private.h +++ b/src/lib/eet/Eet_private.h @@ -33,13 +33,13 @@ struct _Eet_String int next; int prev; - - unsigned char hash; - unsigned char allocated : 1; }; struct _Eet_Dictionary { - Eet_String *all; + Eet_String *all; + unsigned char *all_hash; + unsigned char *all_allocated; + Eina_Hash *converts; Eina_Lock mutex; diff --git a/src/lib/eet/eet_dictionary.c b/src/lib/eet/eet_dictionary.c index aef8ad2721..8bf056a12e 100644 --- a/src/lib/eet/eet_dictionary.c +++ b/src/lib/eet/eet_dictionary.c @@ -36,11 +36,12 @@ eet_dictionary_free(Eet_Dictionary *ed) eina_lock_free(&ed->mutex); 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); - 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); @@ -117,14 +118,24 @@ eet_dictionary_string_add(Eet_Dictionary *ed, if (ed->total == ed->count) { Eet_String *new; + unsigned char *new_hash; + unsigned char *new_allocated; int total; total = ed->total + 8; new = realloc(ed->all, total * sizeof(Eet_String)); if (!new) goto on_error; - 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; } @@ -133,9 +144,8 @@ eet_dictionary_string_add(Eet_Dictionary *ed, current = ed->all + ed->count; - current->allocated = EINA_TRUE; - - current->hash = hash; + ed->all_allocated[ed->count >> 8] |= (1 << (ed->count & 0x7)); + ed->all_hash[ed->count] = hash; current->str = str; current->len = len; @@ -209,7 +219,7 @@ eet_dictionary_string_get_hash(const Eet_Dictionary *ed, eina_lock_take((Eina_Lock*) &ed->mutex); if (idx < ed->count) - hash = ed->all[idx].hash; + hash = ed->all_hash[idx]; eina_lock_release((Eina_Lock*) &ed->mutex); @@ -233,10 +243,10 @@ eet_dictionary_string_get_char(const Eet_Dictionary *ed, { #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. */ - 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].allocated = EINA_TRUE; + ed->all_allocated[idx >> 8] |= (1 << (idx & 0x7)); } #endif /* ifdef _WIN32 */ s = ed->all[idx].str; @@ -500,7 +510,7 @@ eet_dictionary_string_check(Eet_Dictionary *ed, if (!res) { 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; break; diff --git a/src/lib/eet/eet_lib.c b/src/lib/eet/eet_lib.c index 5a0c34eb28..613b83c255 100644 --- a/src/lib/eet/eet_lib.c +++ b/src/lib/eet/eet_lib.c @@ -446,7 +446,7 @@ eet_flush2(Eet_File *ef) { 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[2] = (int)htonl((unsigned int)ef->ed->all[j].len); 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)) 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->total = num_dictionary_entries; ef->ed->start = start + bytes_dictionary_entries + @@ -983,7 +991,7 @@ eet_internal_read2(Eet_File *ef) '\0', ef)) return NULL; - ef->ed->all[j].hash = hash; + ef->ed->all_hash[j] = hash; if (ef->ed->all[j].prev == -1) ef->ed->hash[hash] = j;