From 77bb26025633fc7fabea0a8878c7296962690cf9 Mon Sep 17 00:00:00 2001 From: Cedric BAIL Date: Thu, 17 Jul 2008 15:33:40 +0000 Subject: [PATCH] Improve decode speed by using precomputed hash. SVN revision: 35140 --- legacy/eet/src/lib/eet_data.c | 29 +++++++++++++++++++++++++---- legacy/eet/src/lib/eet_dictionary.c | 22 ++++++++++++++-------- legacy/eet/src/lib/eet_lib.c | 1 + 3 files changed, 40 insertions(+), 12 deletions(-) diff --git a/legacy/eet/src/lib/eet_data.c b/legacy/eet/src/lib/eet_data.c index b899310b89..33496bcc2b 100644 --- a/legacy/eet/src/lib/eet_data.c +++ b/legacy/eet/src/lib/eet_data.c @@ -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; @@ -388,6 +389,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) { @@ -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; diff --git a/legacy/eet/src/lib/eet_dictionary.c b/legacy/eet/src/lib/eet_dictionary.c index a0aea9cb2e..666282bc1a 100644 --- a/legacy/eet/src/lib/eet_dictionary.c +++ b/legacy/eet/src/lib/eet_dictionary.c @@ -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 diff --git a/legacy/eet/src/lib/eet_lib.c b/legacy/eet/src/lib/eet_lib.c index 2b2fdd17a2..23449d38b4 100644 --- a/legacy/eet/src/lib/eet_lib.c +++ b/legacy/eet/src/lib/eet_lib.c @@ -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; }