* eet: fix eet dictionnary ever growing dictionnary.
authorcedric <cedric@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Fri, 3 Sep 2010 13:25:22 +0000 (13:25 +0000)
committercedric <cedric@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Fri, 3 Sep 2010 13:25:22 +0000 (13:25 +0000)
git-svn-id: http://svn.enlightenment.org/svn/e/trunk/eet@51860 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33

ChangeLog
src/lib/eet_dictionary.c

index c627daa..0a8cd3e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
 
 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.
index 23ef3b0..2c7f24c 100644 (file)
@@ -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;