* eet: improve speed for Eet_String users.

SVN revision: 55063
This commit is contained in:
Cedric BAIL 2010-11-29 14:04:16 +00:00
parent 7db2cb388c
commit 1413e6f3b7
4 changed files with 25 additions and 46 deletions

View File

@ -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.

View File

@ -27,10 +27,7 @@ struct _Eet_Convert
struct _Eet_String
{
union {
const char *mmap;
char *str;
} u;
const char *str;
int len;

View File

@ -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;

View File

@ -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;