Improve decode speed by using precomputed hash.
authorcedric <cedric>
Thu, 17 Jul 2008 15:33:40 +0000 (15:33 +0000)
committercedric <cedric@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Thu, 17 Jul 2008 15:33:40 +0000 (15:33 +0000)
git-svn-id: http://svn.enlightenment.org/svn/e/trunk/e17/libs/eet@35140 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33

src/lib/eet_data.c
src/lib/eet_dictionary.c
src/lib/eet_lib.c

index b899310..33496bc 100644 (file)
@@ -101,6 +101,7 @@ struct _Eet_Data_Chunk
    char          *name;
    int            len;
    int            size;
+   int            hash;
    void          *data;
    unsigned char  type;
    unsigned char  group_type;
@@ -389,6 +390,22 @@ eet_data_put_long_long(Eet_Dictionary *ed __UNUSED__, const void *src, int *size
 
 /* 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 @@ eet_data_chunk_get(const Eet_Dictionary *ed, Eet_Data_Chunk *chnk,
      }
 
    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 @@ _eet_descriptor_hash_free(Eet_Data_Descriptor *edd)
 }
 
 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 @@ _eet_data_descriptor_decode(const Eet_Dictionary *ed,
        /* 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;
index a0aea9c..666282b 100644 (file)
@@ -159,22 +159,28 @@ eet_dictionary_string_add(Eet_Dictionary *ed, const char *string)
 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
index 2b2fdd1..23449d3 100644 (file)
@@ -897,6 +897,7 @@ eet_internal_read2(Eet_File *ef)
              /* 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;
           }