From 5465eb3accf8661675ff4c9111328077276fee98 Mon Sep 17 00:00:00 2001 From: Cedric BAIL Date: Fri, 5 Apr 2013 12:14:50 +0900 Subject: [PATCH] eet: remove use of prev to reduce memory usage (30KB on 32bits system). --- src/lib/eet/Eet_private.h | 1 - src/lib/eet/eet_dictionary.c | 23 +++++++++++++---------- src/lib/eet/eet_lib.c | 12 +++++++++--- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/lib/eet/Eet_private.h b/src/lib/eet/Eet_private.h index 87d66c4..af4f75e 100644 --- a/src/lib/eet/Eet_private.h +++ b/src/lib/eet/Eet_private.h @@ -32,7 +32,6 @@ struct _Eet_String int len; int next; - int prev; }; struct _Eet_Dictionary { diff --git a/src/lib/eet/eet_dictionary.c b/src/lib/eet/eet_dictionary.c index bdf141a..b003616 100644 --- a/src/lib/eet/eet_dictionary.c +++ b/src/lib/eet/eet_dictionary.c @@ -52,7 +52,8 @@ static int _eet_dictionary_lookup(Eet_Dictionary *ed, const char *string, int len, - int hash) + int hash, + int *previous) { Eina_Bool found = EINA_FALSE; int prev = -1; @@ -78,8 +79,14 @@ _eet_dictionary_lookup(Eet_Dictionary *ed, } if ((current == -1) && found) - return prev; + { + // WTF ?!? How can current == -1 and found == EINA_TRUE + // If you happen to trigger this abort, contact enlightenment developer mailing list + abort(); + return prev; + } + if (previous) *previous = prev; return current; } @@ -91,6 +98,7 @@ eet_dictionary_string_add(Eet_Dictionary *ed, const char *str; int hash; int idx; + int pidx; int len; int cnt; @@ -102,7 +110,7 @@ eet_dictionary_string_add(Eet_Dictionary *ed, eina_lock_take(&ed->mutex); - idx = _eet_dictionary_lookup(ed, string, len, hash); + idx = _eet_dictionary_lookup(ed, string, len, hash, &pidx); if (idx != -1) { @@ -153,19 +161,14 @@ eet_dictionary_string_add(Eet_Dictionary *ed, if (idx == -1) { current->next = ed->hash[hash]; - current->prev = -1; ed->hash[hash] = ed->count; } else { current->next = idx; - current->prev = ed->all[idx].prev; - - if (current->next != -1) - ed->all[current->next].prev = ed->count; - if (current->prev != -1) - ed->all[current->prev].next = ed->count; + if (pidx != -1) + ed->all[pidx].next = ed->count; else ed->hash[hash] = ed->count; } diff --git a/src/lib/eet/eet_lib.c b/src/lib/eet/eet_lib.c index fd835af..4716f6a 100644 --- a/src/lib/eet/eet_lib.c +++ b/src/lib/eet/eet_lib.c @@ -445,11 +445,16 @@ eet_flush2(Eet_File *ef) for (j = 0; j < ef->ed->count; ++j) { int sbuf[EET_FILE2_DICTIONARY_ENTRY_COUNT]; + int prev = 0; + + // We still use the prev as an hint for knowing if it is the head of the hash + if (ef->ed->hash[ef->ed->all_hash[j]] == j) + prev = -1; 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); + sbuf[3] = (int)htonl((unsigned int)prev); sbuf[4] = (int)htonl((unsigned int)ef->ed->all[j].next); offset += ef->ed->all[j].len; @@ -959,12 +964,13 @@ eet_internal_read2(Eet_File *ef) for (j = 0; j < ef->ed->count; ++j) { unsigned int offset; + int prev; int hash; GET_INT(hash, dico, idx); GET_INT(offset, dico, idx); GET_INT(ef->ed->all[j].len, dico, idx); - GET_INT(ef->ed->all[j].prev, dico, idx); + GET_INT(prev, dico, idx); // Let's ignore prev link for dictionary, use it only as an hint to head GET_INT(ef->ed->all[j].next, dico, idx); /* Hash value could be stored on 8bits data, but this will break alignment of all the others data. @@ -992,7 +998,7 @@ eet_internal_read2(Eet_File *ef) return NULL; ef->ed->all_hash[j] = hash; - if (ef->ed->all[j].prev == -1) + if (prev == -1) ef->ed->hash[hash] = j; /* compute the possible position of a signature */ -- 2.7.4