Enlightenment CVS committal

Author  : cedric
Project : e17
Module  : libs/eet

Dir     : e17/libs/eet/src/lib


Modified Files:
        eet_data.c eet_dictionary.c eet_lib.c 


Log Message:
Improve decode speed by using precomputed hash.


===================================================================
RCS file: /cvs/e/e17/libs/eet/src/lib/eet_data.c,v
retrieving revision 1.86
retrieving revision 1.87
diff -u -3 -r1.86 -r1.87
--- eet_data.c  2 Jul 2008 12:10:12 -0000       1.86
+++ eet_data.c  17 Jul 2008 15:33:40 -0000      1.87
@@ -101,6 +101,7 @@
    char          *name;
    int            len;
    int            size;
+   int            hash;
    void          *data;
    unsigned char  type;
    unsigned char  group_type;
@@ -389,6 +390,22 @@
 
 /* STRING TYPE */
 static int
+eet_data_get_string_hash(const Eet_Dictionary *ed, const void *src, const void 
*src_end)
+{
+   if (ed)
+     {
+        const char       *str;
+        int               index;
+
+        if (eet_data_get_int(ed, src, src_end, &index) < 0) return -1;
+
+        return eet_dictionary_string_get_hash(ed, index);
+     }
+
+   return -1;
+}
+
+static int
 eet_data_get_string(const Eet_Dictionary *ed, const void *src, const void 
*src_end, void *dst)
 {
    char *s, **d;
@@ -718,6 +735,10 @@
      }
 
    chnk->len = ret2;
+
+   /* Precalc hash */
+   chnk->hash = eet_data_get_string_hash(ed, (s + 8), (s + size));
+
    if (ed)
      {
         chnk->data = (char *)src + 4 + ret1 + sizeof(int);
@@ -891,12 +912,12 @@
 }
 
 static Eet_Data_Element *
-_eet_descriptor_hash_find(Eet_Data_Descriptor *edd, char *name)
+_eet_descriptor_hash_find(Eet_Data_Descriptor *edd, char *name, int hash)
 {
-   int hash;
    Eet_Data_Descriptor_Hash *bucket;
 
-   hash = _eet_hash_gen(name, 6);
+   if (hash < 0) hash = _eet_hash_gen(name, 6);
+   else hash &= 0x3f;
    if (!edd->elements.hash.buckets[hash].element) return NULL;
    if (!strcmp(edd->elements.hash.buckets[hash].element->name, name))
      return edd->elements.hash.buckets[hash].element;
@@ -2113,7 +2134,7 @@
        /* FIXME: don't REPLY on edd - work without */
        if ((edd) && (!dumpfunc))
          {
-            ede = _eet_descriptor_hash_find(edd, echnk.name);
+            ede = _eet_descriptor_hash_find(edd, echnk.name, echnk.hash);
             if (ede)
               {
                  int group_type = EET_G_UNKNOWN, type = EET_T_UNKNOW;
===================================================================
RCS file: /cvs/e/e17/libs/eet/src/lib/eet_dictionary.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -3 -r1.5 -r1.6
--- eet_dictionary.c    28 Mar 2008 17:17:43 -0000      1.5
+++ eet_dictionary.c    17 Jul 2008 15:33:40 -0000      1.6
@@ -159,22 +159,28 @@
 int
 eet_dictionary_string_get_size(const Eet_Dictionary *ed, int index)
 {
-   if (!ed)
-     return 0;
-   if (index < 0)
-     return 0;
+   if (!ed) return 0;
+   if (index < 0) return 0;
    if (index < ed->count)
      return ed->all[index].len;
    return 0;
 }
 
+int
+eet_dictionary_string_get_hash(const Eet_Dictionary *ed, int index)
+{
+   if (!ed) return -1;
+   if (index < 0) return -1;
+   if (index < ed->count)
+     return ed->all[index].hash;
+   return -1;
+}
+
 const char *
 eet_dictionary_string_get_char(const Eet_Dictionary *ed, int index)
 {
-   if (!ed)
-     return NULL;
-   if (index < 0)
-     return NULL;
+   if (!ed) return NULL;
+   if (index < 0) return NULL;
    if (index < ed->count)
      {
 #ifdef _WIN32
===================================================================
RCS file: /cvs/e/e17/libs/eet/src/lib/eet_lib.c,v
retrieving revision 1.111
retrieving revision 1.112
diff -u -3 -r1.111 -r1.112
--- eet_lib.c   27 Jun 2008 22:05:49 -0000      1.111
+++ eet_lib.c   17 Jul 2008 15:33:40 -0000      1.112
@@ -897,6 +897,7 @@
              /* Check '\0' at the end of the string */
              if (eet_test_close(ef->ed->all[j].mmap[ef->ed->all[j].len - 1] != 
'\0', ef)) return NULL;
 
+            ef->ed->all[j].hash = hash;
              if (ef->ed->all[j].prev == -1)
                ef->ed->hash[hash] = j;
           }



-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
enlightenment-cvs mailing list
enlightenment-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to