From: cedric Date: Fri, 3 Sep 2010 13:25:22 +0000 (+0000) Subject: * eet: fix eet dictionnary ever growing dictionnary. X-Git-Tag: 1.0_branch~247 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e49b9cec9ae49da184dc82663a851e7bf9f8cfc1;p=profile%2Fivi%2Feet.git * eet: fix eet dictionnary ever growing dictionnary. git-svn-id: http://svn.enlightenment.org/svn/e/trunk/eet@51860 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33 --- diff --git a/ChangeLog b/ChangeLog index c627daa..0a8cd3e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -434,5 +434,9 @@ 2010-08-27 Cedric BAIL - * prevent the build of eet data structure that doesn't match what + * Prevent the build of eet data structure that doesn't match what the application is expecting. + +2010-09-02 Cedric BAIL + + * Fix bug of ever growing dictionnary and improve strcmp comparison. diff --git a/src/lib/eet_dictionary.c b/src/lib/eet_dictionary.c index 23ef3b0..2c7f24c 100644 --- a/src/lib/eet_dictionary.c +++ b/src/lib/eet_dictionary.c @@ -46,8 +46,10 @@ eet_dictionary_free(Eet_Dictionary *ed) static int _eet_dictionary_lookup(Eet_Dictionary *ed, const char *string, + int len, int hash) { + Eina_Bool found = EINA_FALSE; int prev = -1; int current; @@ -55,19 +57,28 @@ _eet_dictionary_lookup(Eet_Dictionary *ed, while (current != -1) { - if (ed->all[current].str) - if (strcmp(ed->all[current].str, string) >= 0) - break; - - if (ed->all[current].mmap) - if (strcmp(ed->all[current].mmap, string) >= 0) - break; + if (ed->all[current].len == len) + { + if (ed->all[current].str) + if (strcmp(ed->all[current].str, string) == 0) + { + found = EINA_TRUE; + break; + } + + if (ed->all[current].mmap) + if (strcmp(ed->all[current].mmap, string) == 0) + { + found = EINA_TRUE; + break; + } + } prev = current; current = ed->all[current].next; } - if (current == -1) + if (current == -1 && found) return prev; return current; @@ -87,19 +98,19 @@ eet_dictionary_string_add(Eet_Dictionary *ed, return -1; hash = _eet_hash_gen(string, 8); + len = strlen(string) + 1; - idx = _eet_dictionary_lookup(ed, string, hash); + idx = _eet_dictionary_lookup(ed, string, len, hash); if (idx != -1) { if (ed->all[idx].str) - if (strcmp(ed->all[idx].str, string) == 0) - return idx; + if (strcmp(ed->all[idx].str, string) == 0) + return idx; if (ed->all[idx].mmap) - if (strcmp(ed->all[idx].mmap, string) == 0) - return idx; - + if (strcmp(ed->all[idx].mmap, string) == 0) + return idx; } if (ed->total == ed->count) @@ -117,7 +128,6 @@ eet_dictionary_string_add(Eet_Dictionary *ed, ed->total = total; } - len = strlen(string) + 1; str = strdup(string); if (!str) return -1;