forked from enlightenment/efl
* eet: improve speed for Eet_String users.
SVN revision: 55063
This commit is contained in:
parent
7db2cb388c
commit
1413e6f3b7
|
@ -462,3 +462,8 @@
|
||||||
|
|
||||||
* Reduce memory used by Eet dictionary.
|
* 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.
|
||||||
|
|
||||||
|
|
|
@ -27,10 +27,7 @@ struct _Eet_Convert
|
||||||
|
|
||||||
struct _Eet_String
|
struct _Eet_String
|
||||||
{
|
{
|
||||||
union {
|
const char *str;
|
||||||
const char *mmap;
|
|
||||||
char *str;
|
|
||||||
} u;
|
|
||||||
|
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ eet_dictionary_free(Eet_Dictionary *ed)
|
||||||
|
|
||||||
for (i = 0; i < ed->count; ++i)
|
for (i = 0; i < ed->count; ++i)
|
||||||
if (ed->all[i].allocated)
|
if (ed->all[i].allocated)
|
||||||
free(ed->all[i].u.str);
|
eina_stringshare_del(ed->all[i].str);
|
||||||
|
|
||||||
if (ed->all)
|
if (ed->all)
|
||||||
free(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].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;
|
prev = current;
|
||||||
|
@ -92,7 +84,7 @@ eet_dictionary_string_add(Eet_Dictionary *ed,
|
||||||
const char *string)
|
const char *string)
|
||||||
{
|
{
|
||||||
Eet_String *current;
|
Eet_String *current;
|
||||||
char *str;
|
const char *str;
|
||||||
int hash;
|
int hash;
|
||||||
int idx;
|
int idx;
|
||||||
int len;
|
int len;
|
||||||
|
@ -107,12 +99,7 @@ eet_dictionary_string_add(Eet_Dictionary *ed,
|
||||||
|
|
||||||
if (idx != -1)
|
if (idx != -1)
|
||||||
{
|
{
|
||||||
if (ed->all[idx].allocated)
|
if (ed->all[idx].str && (ed->all[idx].str == string || strcmp(ed->all[idx].str, string) == 0))
|
||||||
{
|
|
||||||
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)
|
|
||||||
return idx;
|
return idx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,7 +118,7 @@ eet_dictionary_string_add(Eet_Dictionary *ed,
|
||||||
ed->total = total;
|
ed->total = total;
|
||||||
}
|
}
|
||||||
|
|
||||||
str = strdup(string);
|
str = eina_stringshare_add(string);
|
||||||
if (!str)
|
if (!str)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
@ -141,7 +128,7 @@ eet_dictionary_string_add(Eet_Dictionary *ed,
|
||||||
|
|
||||||
current->hash = hash;
|
current->hash = hash;
|
||||||
|
|
||||||
current->u.str = str;
|
current->str = str;
|
||||||
current->len = len;
|
current->len = len;
|
||||||
|
|
||||||
if (idx == -1)
|
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. */
|
/* 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)
|
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;
|
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 */
|
#endif /* ifdef _WIN32 */
|
||||||
return ed->all[idx].u.str;
|
return ed->all[idx].str;
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -316,7 +298,7 @@ eet_dictionary_convert_get(const Eet_Dictionary *ed,
|
||||||
{
|
{
|
||||||
Eet_Convert *result;
|
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)
|
if (!ed->converts)
|
||||||
{
|
{
|
||||||
|
@ -449,7 +431,7 @@ eet_dictionary_string_check(Eet_Dictionary *ed,
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
for (i = 0; i < ed->count; ++i)
|
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 1;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -636,13 +636,8 @@ eet_flush2(Eet_File *ef)
|
||||||
if (ef->ed)
|
if (ef->ed)
|
||||||
for (j = 0; j < ef->ed->count; ++j)
|
for (j = 0; j < ef->ed->count; ++j)
|
||||||
{
|
{
|
||||||
if (ef->ed->all[j].allocated)
|
if (fwrite(ef->ed->all[j].str, ef->ed->all[j].len, 1, fp) != 1)
|
||||||
{
|
goto write_error;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* write data */
|
/* write data */
|
||||||
|
@ -1082,13 +1077,13 @@ eet_internal_read2(Eet_File *ef)
|
||||||
ef->data_size)), ef))
|
ef->data_size)), ef))
|
||||||
return NULL;
|
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)
|
if (ef->ed->all[j].str + ef->ed->all[j].len > ef->ed->end)
|
||||||
ef->ed->end = ef->ed->all[j].u.mmap + ef->ed->all[j].len;
|
ef->ed->end = ef->ed->all[j].str + ef->ed->all[j].len;
|
||||||
|
|
||||||
/* Check '\0' at the end of the string */
|
/* 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))
|
'\0', ef))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue