diff options
author | Cedric BAIL <cedric.bail@free.fr> | 2010-11-29 14:04:16 +0000 |
---|---|---|
committer | Cedric BAIL <cedric.bail@free.fr> | 2010-11-29 14:04:16 +0000 |
commit | 39cb76aa0896950c9d836b2815856eff5d522823 (patch) | |
tree | ab92124e3b856892e3019a7f2f9724af6c1fec1a | |
parent | 6c2b478ee719bb2a3631d594c9f0143b23a12617 (diff) | |
download | eet-39cb76aa0896950c9d836b2815856eff5d522823.tar.gz |
* eet: improve speed for Eet_String users.
SVN revision: 55063
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | src/lib/Eet_private.h | 5 | ||||
-rw-r--r-- | src/lib/eet_dictionary.c | 44 | ||||
-rw-r--r-- | src/lib/eet_lib.c | 17 |
4 files changed, 25 insertions, 46 deletions
@@ -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/src/lib/Eet_private.h b/src/lib/Eet_private.h index e6e178b..1b7b9de 100644 --- a/src/lib/Eet_private.h +++ b/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/src/lib/eet_dictionary.c b/src/lib/eet_dictionary.c index 70f0eb3..566f148 100644 --- a/src/lib/eet_dictionary.c +++ b/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/src/lib/eet_lib.c b/src/lib/eet_lib.c index d3d4158..d67c5e8 100644 --- a/src/lib/eet_lib.c +++ b/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; |