From: Cedric BAIL Date: Sun, 29 Sep 2013 11:14:22 +0000 (+0200) Subject: evas: let's micro optimize the parsing of format. X-Git-Tag: submit/devel/efl/20131029.075644~162 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5d37215d261da2cb6b42070e8608cdec702d8269;p=platform%2Fupstream%2Fefl.git evas: let's micro optimize the parsing of format. Only the key is worth being a stringshare as it is used to do an efficient binary comparison instead of iterating over all possibility. Also reused some already known value and a few other speedup. --- diff --git a/src/lib/evas/canvas/evas_object_textblock.c b/src/lib/evas/canvas/evas_object_textblock.c index cf242fe..37bd6a3 100644 --- a/src/lib/evas/canvas/evas_object_textblock.c +++ b/src/lib/evas/canvas/evas_object_textblock.c @@ -1028,11 +1028,8 @@ _hex_string_get(char ch) * @param[out] a The Alpha value - NOT NULL. */ static void -_format_color_parse(const char *str, unsigned char *r, unsigned char *g, unsigned char *b, unsigned char *a) +_format_color_parse(const char *str, int slen, unsigned char *r, unsigned char *g, unsigned char *b, unsigned char *a) { - int slen; - - slen = strlen(str); *r = *g = *b = *a = 0; if (slen == 7) /* #RRGGBB */ @@ -1277,19 +1274,22 @@ _format_command_shutdown(void) * @param[out] dst the destination string - Should not be NULL. * @param[in] src the source string - Should not be NULL. */ -static void -_format_clean_param(char *dst, const char *src) +static int +_format_clean_param(Eina_Tmpstr *s) { - const char *ss; + Eina_Tmpstr *ss; char *ds; + int len = 0; - ds = dst; - for (ss = src; *ss; ss++, ds++) + ds = (char*) s; + for (ss = s; *ss; ss++, ds++, len++) { if ((*ss == '\\') && *(ss + 1)) ss++; - *ds = *ss; + if (ds != ss) *ds = *ss; } *ds = 0; + + return len; } /** @@ -1302,15 +1302,11 @@ _format_clean_param(char *dst, const char *src) * @param[in] param the parameter of the command. */ static void -_format_command(Evas_Object *eo_obj, Evas_Object_Textblock_Format *fmt, const char *cmd, const char *param) +_format_command(Evas_Object *eo_obj, Evas_Object_Textblock_Format *fmt, const char *cmd, Eina_Tmpstr *param) { int len; - char *tmp_param; - - len = strlen(param); - tmp_param = alloca(len + 1); - _format_clean_param(tmp_param, param); + len = _format_clean_param(param); /* If we are changing the font, create the fdesc. */ if ((cmd == font_weightstr) || (cmd == font_widthstr) || @@ -1342,7 +1338,7 @@ _format_command(Evas_Object *eo_obj, Evas_Object_Textblock_Format *fmt, const ch * font= * @endcode */ - evas_font_name_parse(fmt->font.fdesc, tmp_param); + evas_font_name_parse(fmt->font.fdesc, param); } else if (cmd == font_fallbacksstr) { @@ -1357,7 +1353,7 @@ _format_command(Evas_Object *eo_obj, Evas_Object_Textblock_Format *fmt, const ch * font_fallbacks= * @endcode */ - eina_stringshare_replace(&(fmt->font.fdesc->fallbacks), tmp_param); + eina_stringshare_replace(&(fmt->font.fdesc->fallbacks), param); } else if (cmd == font_sizestr) { @@ -1373,7 +1369,7 @@ _format_command(Evas_Object *eo_obj, Evas_Object_Textblock_Format *fmt, const ch */ int v; - v = atoi(tmp_param); + v = atoi(param); if (v != fmt->font.size) { fmt->font.size = v; @@ -1392,10 +1388,9 @@ _format_command(Evas_Object *eo_obj, Evas_Object_Textblock_Format *fmt, const ch * @endcode */ if ((!fmt->font.source) || - ((fmt->font.source) && (strcmp(fmt->font.source, tmp_param)))) + ((fmt->font.source) && (strcmp(fmt->font.source, param)))) { - if (fmt->font.source) eina_stringshare_del(fmt->font.source); - fmt->font.source = eina_stringshare_add(tmp_param); + eina_stringshare_replace(&(fmt->font.source), param); } } else if (cmd == font_weightstr) @@ -1421,8 +1416,9 @@ _format_command(Evas_Object *eo_obj, Evas_Object_Textblock_Format *fmt, const ch * font_weight= * @endcode */ - fmt->font.fdesc->weight = evas_font_style_find(tmp_param, - tmp_param + strlen(tmp_param), EVAS_FONT_STYLE_WEIGHT); + fmt->font.fdesc->weight = evas_font_style_find(param, + param + len, + EVAS_FONT_STYLE_WEIGHT); } else if (cmd == font_stylestr) { @@ -1439,8 +1435,9 @@ _format_command(Evas_Object *eo_obj, Evas_Object_Textblock_Format *fmt, const ch * font_style=