From 1413e6f3b784ad5708e2282433e4545d7b5f9863 Mon Sep 17 00:00:00 2001 From: Cedric BAIL Date: Mon, 29 Nov 2010 14:04:16 +0000 Subject: [PATCH] * eet: improve speed for Eet_String users. SVN revision: 55063 --- legacy/eet/ChangeLog | 5 ++++ legacy/eet/src/lib/Eet_private.h | 5 +--- legacy/eet/src/lib/eet_dictionary.c | 44 +++++++++-------------------- legacy/eet/src/lib/eet_lib.c | 17 ++++------- 4 files changed, 25 insertions(+), 46 deletions(-) diff --git a/legacy/eet/ChangeLog b/legacy/eet/ChangeLog index e541eb7932..bc8d2ec2e0 100644 --- a/legacy/eet/ChangeLog +++ b/legacy/eet/ChangeLog @@ -462,3 +462,8 @@ * Reduce memory used by Eet dictionary. +2010-11-29 Cedric BAIL + + * Improve speed of Eet_String users. It does impact all string + encoding/decoding, but even faster for stringshare encoding. + diff --git a/legacy/eet/src/lib/Eet_private.h b/legacy/eet/src/lib/Eet_private.h index e6e178b34d..1b7b9deaec 100644 --- a/legacy/eet/src/lib/Eet_private.h +++ b/legacy/eet/src/lib/Eet_private.h @@ -27,10 +27,7 @@ struct _Eet_Convert struct _Eet_String { - union { - const char *mmap; - char *str; - } u; + const char *str; int len; diff --git a/legacy/eet/src/lib/eet_dictionary.c b/legacy/eet/src/lib/eet_dictionary.c index 70f0eb3bb8..566f1484df 100644 --- a/legacy/eet/src/lib/eet_dictionary.c +++ b/legacy/eet/src/lib/eet_dictionary.c @@ -34,7 +34,7 @@ eet_dictionary_free(Eet_Dictionary *ed) for (i = 0; i < ed->count; ++i) if (ed->all[i].allocated) - free(ed->all[i].u.str); + eina_stringshare_del(ed->all[i].str); if (ed->all) free(ed->all); @@ -61,20 +61,12 @@ _eet_dictionary_lookup(Eet_Dictionary *ed, { if (ed->all[current].len == len) { - if (ed->all[current].allocated) + if (ed->all[current].str && + (ed->all[current].str == string || strcmp(ed->all[current].str, string) == 0)) { - if (strcmp(ed->all[current].u.str, string) == 0) - { - found = EINA_TRUE; - break; - } + found = EINA_TRUE; + break; } - else if (ed->all[current].u.mmap - && strcmp(ed->all[current].u.mmap, string) == 0) - { - found = EINA_TRUE; - break; - } } prev = current; @@ -92,7 +84,7 @@ eet_dictionary_string_add(Eet_Dictionary *ed, const char *string) { Eet_String *current; - char *str; + const char *str; int hash; int idx; int len; @@ -107,12 +99,7 @@ eet_dictionary_string_add(Eet_Dictionary *ed, if (idx != -1) { - if (ed->all[idx].allocated) - { - if (strcmp(ed->all[idx].u.str, string) == 0) - return idx; - } - else if (ed->all[idx].u.mmap && strcmp(ed->all[idx].u.mmap, string) == 0) + if (ed->all[idx].str && (ed->all[idx].str == string || strcmp(ed->all[idx].str, string) == 0)) return idx; } @@ -131,7 +118,7 @@ eet_dictionary_string_add(Eet_Dictionary *ed, ed->total = total; } - str = strdup(string); + str = eina_stringshare_add(string); if (!str) return -1; @@ -141,7 +128,7 @@ eet_dictionary_string_add(Eet_Dictionary *ed, current->hash = hash; - current->u.str = str; + current->str = str; current->len = len; if (idx == -1) @@ -215,16 +202,11 @@ eet_dictionary_string_get_char(const Eet_Dictionary *ed, /* Windows file system could change the mmaped file when replacing a file. So we need to copy all string in memory to avoid bugs. */ if (!ed->all[idx].allocated) { - ed->all[idx].u.str = strdup(ed->all[idx].u.mmap); + ed->all[idx].str = strdup(ed->all[idx].str); ed->all[idx].allocated = EINA_TRUE; } - -#else /* ifdef _WIN32 */ - if (!(ed->all[idx].allocated) && ed->all[idx].u.mmap) - return ed->all[idx].u.mmap; - #endif /* ifdef _WIN32 */ - return ed->all[idx].u.str; + return ed->all[idx].str; } return NULL; @@ -316,7 +298,7 @@ eet_dictionary_convert_get(const Eet_Dictionary *ed, { Eet_Convert *result; - *str = ed->all[idx].allocated ? ed->all[idx].u.str : ed->all[idx].u.mmap; + *str = ed->all[idx].str; if (!ed->converts) { @@ -449,7 +431,7 @@ eet_dictionary_string_check(Eet_Dictionary *ed, return 1; for (i = 0; i < ed->count; ++i) - if ((ed->all[i].allocated) && ed->all[i].u.str == string) + if ((ed->all[i].allocated) && ed->all[i].str == string) return 1; return 0; diff --git a/legacy/eet/src/lib/eet_lib.c b/legacy/eet/src/lib/eet_lib.c index d3d415826d..d67c5e8da1 100644 --- a/legacy/eet/src/lib/eet_lib.c +++ b/legacy/eet/src/lib/eet_lib.c @@ -636,13 +636,8 @@ eet_flush2(Eet_File *ef) if (ef->ed) for (j = 0; j < ef->ed->count; ++j) { - if (ef->ed->all[j].allocated) - { - if (fwrite(ef->ed->all[j].u.str, ef->ed->all[j].len, 1, fp) != 1) - goto write_error; - } - else if (fwrite(ef->ed->all[j].u.mmap, ef->ed->all[j].len, 1, fp) != 1) - goto write_error; + if (fwrite(ef->ed->all[j].str, ef->ed->all[j].len, 1, fp) != 1) + goto write_error; } /* write data */ @@ -1082,13 +1077,13 @@ eet_internal_read2(Eet_File *ef) ef->data_size)), ef)) return NULL; - ef->ed->all[j].u.mmap = start + offset; + ef->ed->all[j].str = start + offset; - if (ef->ed->all[j].u.mmap + ef->ed->all[j].len > ef->ed->end) - ef->ed->end = ef->ed->all[j].u.mmap + ef->ed->all[j].len; + if (ef->ed->all[j].str + ef->ed->all[j].len > ef->ed->end) + ef->ed->end = ef->ed->all[j].str + ef->ed->all[j].len; /* Check '\0' at the end of the string */ - if (eet_test_close(ef->ed->all[j].u.mmap[ef->ed->all[j].len - 1] != + if (eet_test_close(ef->ed->all[j].str[ef->ed->all[j].len - 1] != '\0', ef)) return NULL;