edje/style: refactor style parsing to remove temporary dynamic string creation.

Summary:
pass a buffer to reparse() function for reuse.
create fontsource once and reuse.

Reviewers: ali.alzyod, Hermet, cedric, raster

Reviewed By: Hermet

Subscribers: cedric, #reviewers, #committers

Tags: #efl

Differential Revision: https://phab.enlightenment.org/D9636
This commit is contained in:
subhransu mohanty 2019-08-20 14:36:22 +09:00 committed by Hermet Park
parent 5c39e68d2b
commit 6f0730cef3
1 changed files with 37 additions and 51 deletions

View File

@ -52,14 +52,12 @@ _edje_format_parse(const char **s)
return NULL; return NULL;
} }
static char * static void
_edje_format_reparse(Edje_File *edf, const char *str, Edje_Style_Tag **tag_ret) _edje_format_reparse(Edje_File *edf, const char *str, Edje_Style_Tag *tag_ret, Eina_Strbuf *result)
{ {
Eina_Strbuf *txt, *tmp = NULL; char *s2, *item;
char *s2, *item, *ret;
const char *s; const char *s;
txt = eina_strbuf_new();
s = str; s = str;
while ((item = _edje_format_parse(&s))) while ((item = _edje_format_parse(&s)))
{ {
@ -77,17 +75,18 @@ _edje_format_reparse(Edje_File *edf, const char *str, Edje_Style_Tag **tag_ret)
else if (!strncmp(key, "text_class", key_len)) else if (!strncmp(key, "text_class", key_len))
{ {
if (tag_ret) if (tag_ret)
(*tag_ret)->text_class = eina_stringshare_add(val); tag_ret->text_class = eina_stringshare_add(val);
// no need to add text_class tag to style // no need to add text_class tag to style
// as evas_textblock_style has no idea about // as evas_textblock_style has no idea about
// text_class tag. // text_class tag.
free(item);
continue; continue;
} }
else if (!strncmp(key, "font_size", key_len)) else if (!strncmp(key, "font_size", key_len))
{ {
if (tag_ret) if (tag_ret)
(*tag_ret)->font_size = atof(val); tag_ret->font_size = atof(val);
} }
else if (!strncmp(key, "font", key_len)) /* Fix fonts */ else if (!strncmp(key, "font", key_len)) /* Fix fonts */
{ {
@ -95,39 +94,31 @@ _edje_format_reparse(Edje_File *edf, const char *str, Edje_Style_Tag **tag_ret)
{ {
if (_edje_font_is_embedded(edf, val)) if (_edje_font_is_embedded(edf, val))
{ {
if (!tmp) char buffer[120];
tmp = eina_strbuf_new(); snprintf(buffer, sizeof(buffer), "edje/fonts/%s", val);
eina_strbuf_append(tmp, "edje/fonts/"); tag_ret->font = eina_stringshare_add(buffer);
eina_strbuf_append(tmp, val);
(*tag_ret)->font = eina_stringshare_add(eina_strbuf_string_get(tmp));
eina_strbuf_reset(tmp);
} }
else else
{ {
(*tag_ret)->font = eina_stringshare_add(val); tag_ret->font = eina_stringshare_add(val);
} }
} }
} }
s2 = eina_str_escape(item); s2 = eina_str_escape(item);
if (s2) if (s2)
{ {
if (eina_strbuf_length_get(txt)) eina_strbuf_append(txt, " "); if (eina_strbuf_length_get(result)) eina_strbuf_append(result, " ");
eina_strbuf_append(txt, s2); eina_strbuf_append(result, s2);
free(s2); free(s2);
} }
} }
else else
{ {
if (eina_strbuf_length_get(txt)) eina_strbuf_append(txt, " "); if (eina_strbuf_length_get(result)) eina_strbuf_append(result, " ");
eina_strbuf_append(txt, item); eina_strbuf_append(result, item);
} }
free(item); free(item);
} }
if (tmp)
eina_strbuf_free(tmp);
ret = eina_strbuf_string_steal(txt);
eina_strbuf_free(txt);
return ret;
} }
@ -412,77 +403,72 @@ _edje_textblock_styles_cache_free(Edje *ed, const char *text_class)
void void
_edje_textblock_style_parse_and_fix(Edje_File *edf) _edje_textblock_style_parse_and_fix(Edje_File *edf)
{ {
Eina_Strbuf *txt = NULL;
Eina_List *l, *ll; Eina_List *l, *ll;
Edje_Style *stl; Edje_Style *stl;
char *fontset = _edje_fontset_append_escaped; char *fontset = _edje_fontset_append_escaped;
Eina_Strbuf *reparseBuffer = eina_strbuf_new();
Eina_Strbuf *styleBuffer = eina_strbuf_new();
char *fontsource = edf->fonts ? eina_str_escape(edf->path) : NULL;
EINA_LIST_FOREACH(edf->styles, l, stl) EINA_LIST_FOREACH(edf->styles, l, stl)
{ {
Edje_Style_Tag *tag; Edje_Style_Tag *tag;
char *fontsource = NULL, *ts;
if (stl->style) break; if (stl->style) break;
stl->readonly = EINA_TRUE; stl->readonly = EINA_TRUE;
if (!txt)
txt = eina_strbuf_new();
stl->style = evas_textblock_style_new(); stl->style = evas_textblock_style_new();
evas_textblock_style_set(stl->style, NULL); evas_textblock_style_set(stl->style, NULL);
if (edf->fonts) eina_strbuf_reset(styleBuffer);
fontsource = eina_str_escape(edf->path);
/* Build the style from each tag */ /* Build the style from each tag */
EINA_LIST_FOREACH(stl->tags, ll, tag) EINA_LIST_FOREACH(stl->tags, ll, tag)
{ {
if (!tag->key) continue; if (!tag->key) continue;
/* Add Tag Key */ eina_strbuf_reset(reparseBuffer);
eina_strbuf_append(txt, tag->key);
eina_strbuf_append(txt, "='");
ts = _edje_format_reparse(edf, tag->value, &(tag)); /* Add Tag Key */
eina_strbuf_append(styleBuffer, tag->key);
eina_strbuf_append(styleBuffer, "='");
_edje_format_reparse(edf, tag->value, tag, reparseBuffer);
/* Add and Handle tag parsed data */ /* Add and Handle tag parsed data */
if (ts) if (eina_strbuf_length_get(reparseBuffer))
{ {
if (edf->allocated_strings && if (edf->allocated_strings &&
eet_dictionary_string_check(eet_dictionary_get(edf->ef), tag->value) == 0) eet_dictionary_string_check(eet_dictionary_get(edf->ef), tag->value) == 0)
eina_stringshare_del(tag->value); eina_stringshare_del(tag->value);
tag->value = eina_stringshare_add(ts); tag->value = eina_stringshare_add(eina_strbuf_string_get(reparseBuffer));
eina_strbuf_append(txt, tag->value); eina_strbuf_append(styleBuffer, tag->value);
free(ts);
} }
if (!strcmp(tag->key, "DEFAULT")) if (!strcmp(tag->key, "DEFAULT"))
{ {
if (fontset) if (fontset)
{ {
eina_strbuf_append(txt, " font_fallbacks="); eina_strbuf_append(styleBuffer, " font_fallbacks=");
eina_strbuf_append(txt, fontset); eina_strbuf_append(styleBuffer, fontset);
} }
if (fontsource) if (fontsource)
{ {
eina_strbuf_append(txt, " "); eina_strbuf_append(styleBuffer, " font_source=");
eina_strbuf_append(txt, "font_source="); eina_strbuf_append(styleBuffer, fontsource);
eina_strbuf_append(txt, fontsource);
} }
} }
eina_strbuf_append(txt, "'"); eina_strbuf_append(styleBuffer, "'");
if (tag->text_class) stl->readonly = EINA_FALSE; if (tag->text_class) stl->readonly = EINA_FALSE;
} }
if (fontsource) free(fontsource);
/* Configure the style */ /* Configure the style */
evas_textblock_style_set(stl->style, eina_strbuf_string_get(txt)); evas_textblock_style_set(stl->style, eina_strbuf_string_get(styleBuffer));
eina_strbuf_reset(txt);
} }
if (txt)
eina_strbuf_free(txt); if (fontsource) free(fontsource);
eina_strbuf_free(styleBuffer);
eina_strbuf_free(reparseBuffer);
} }
void void