summaryrefslogtreecommitdiff
path: root/src/lib/evas/canvas/evas_object_textblock.c
diff options
context:
space:
mode:
authorsubhransu mohanty <sub.mohanty@samsung.com>2019-08-12 02:42:27 +0000
committerCedric BAIL <cedric.bail@free.fr>2019-08-12 10:13:30 -0700
commit9952b9bf182d2b27de05b82476649a1ed8c1785d (patch)
tree5fcd79708d186ae3c73fa6c31a18cdea2da08da7 /src/lib/evas/canvas/evas_object_textblock.c
parent384765b08818a63893b6aa001d0bcc481d2366b4 (diff)
textblock/optimization: refactor evas_textblock_style for memory and perfromance.
the main user of textblock_style_set() api is the edje whcih keeps its owen edje_textblock_style tags( string_shared string) by changing the textblock to keep the string_shared string will improve the chance of sharing the same string hence reducing memory. By removing the Eina_StrBuf usage inside the loop in textblock_style_set() api we can avoid lot of temporary memory allocation and deallocation hence will improve performance. Note: I see lot of places we use Eina_Strbuf inside a loop (eina_strbuf_new() does 2 allocation) We need to be extra carefull while reviewing when the code uses those construct to see if its really necessary. Data: it reduces memory allocation by 7000 in elementary_test launch time. Reviewed-by: Cedric BAIL <cedric.bail@free.fr> Differential Revision: https://phab.enlightenment.org/D9545
Diffstat (limited to 'src/lib/evas/canvas/evas_object_textblock.c')
-rw-r--r--src/lib/evas/canvas/evas_object_textblock.c57
1 files changed, 20 insertions, 37 deletions
diff --git a/src/lib/evas/canvas/evas_object_textblock.c b/src/lib/evas/canvas/evas_object_textblock.c
index 4f3f4d5..6ecc9b1 100644
--- a/src/lib/evas/canvas/evas_object_textblock.c
+++ b/src/lib/evas/canvas/evas_object_textblock.c
@@ -307,8 +307,8 @@ typedef struct _Text_Item_Filter Text_Item_Filter;
307 307
308struct _Evas_Object_Style_Tag_Base 308struct _Evas_Object_Style_Tag_Base
309{ 309{
310 char *tag; /**< Format Identifier: b=Bold, i=Italic etc. */ 310 const char *tag; /**< Format Identifier: b=Bold, i=Italic etc. */
311 char *replace; /**< Replacement string. "font_weight=Bold", "font_style=Italic" etc. */ 311 const char *replace; /**< Replacement string. "font_weight=Bold", "font_style=Italic" etc. */
312 size_t tag_len; /**< Strlen of tag. */ 312 size_t tag_len; /**< Strlen of tag. */
313}; 313};
314 314
@@ -552,7 +552,7 @@ struct _Evas_Object_Textblock_Format
552struct _Efl_Canvas_Text_Style 552struct _Efl_Canvas_Text_Style
553{ 553{
554 const char *style_text; 554 const char *style_text;
555 char *default_tag; 555 const char *default_tag;
556 Evas_Object_Style_Tag *tags; 556 Evas_Object_Style_Tag *tags;
557 Eina_List *objects; 557 Eina_List *objects;
558 Eina_Bool delete_me : 1; 558 Eina_Bool delete_me : 1;
@@ -874,15 +874,15 @@ static void
874_style_replace(Evas_Textblock_Style *ts, const char *style_text) 874_style_replace(Evas_Textblock_Style *ts, const char *style_text)
875{ 875{
876 eina_stringshare_replace(&ts->style_text, style_text); 876 eina_stringshare_replace(&ts->style_text, style_text);
877 if (ts->default_tag) free(ts->default_tag); 877 if (ts->default_tag) eina_stringshare_del(ts->default_tag);
878 while (ts->tags) 878 while (ts->tags)
879 { 879 {
880 Evas_Object_Style_Tag *tag; 880 Evas_Object_Style_Tag *tag;
881 881
882 tag = (Evas_Object_Style_Tag *)ts->tags; 882 tag = (Evas_Object_Style_Tag *)ts->tags;
883 ts->tags = (Evas_Object_Style_Tag *)eina_inlist_remove(EINA_INLIST_GET(ts->tags), EINA_INLIST_GET(tag)); 883 ts->tags = (Evas_Object_Style_Tag *)eina_inlist_remove(EINA_INLIST_GET(ts->tags), EINA_INLIST_GET(tag));
884 free(tag->tag.tag); 884 eina_stringshare_del(tag->tag.tag);
885 free(tag->tag.replace); 885 eina_stringshare_del(tag->tag.replace);
886 free(tag); 886 free(tag);
887 } 887 }
888 ts->default_tag = NULL; 888 ts->default_tag = NULL;
@@ -7319,6 +7319,7 @@ evas_textblock_style_set(Evas_Textblock_Style *ts, const char *text)
7319 7319
7320 key_start = key_stop = val_start = NULL; 7320 key_start = key_stop = val_start = NULL;
7321 p = ts->style_text; 7321 p = ts->style_text;
7322 Eina_Strbuf *tag_value_buf = eina_strbuf_new();
7322 while (*p) 7323 while (*p)
7323 { 7324 {
7324 if (!key_start) 7325 if (!key_start)
@@ -7344,12 +7345,13 @@ evas_textblock_style_set(Evas_Textblock_Style *ts, const char *text)
7344 } 7345 }
7345 if ((key_start) && (key_stop) && (val_start)) 7346 if ((key_start) && (key_stop) && (val_start))
7346 { 7347 {
7347 char *tags, *replaces = NULL; 7348 const char *tag_value = NULL;
7348 Evas_Object_Style_Tag *tag; 7349 Evas_Object_Style_Tag *tag;
7349 const char *val_stop = NULL; 7350 const char *val_stop = NULL;
7351
7352 eina_strbuf_reset(tag_value_buf);
7350 size_t tag_len; 7353 size_t tag_len;
7351 { 7354 {
7352 Eina_Strbuf *buf = eina_strbuf_new();
7353 val_stop = val_start; 7355 val_stop = val_start;
7354 while(*p) 7356 while(*p)
7355 { 7357 {
@@ -7358,72 +7360,53 @@ evas_textblock_style_set(Evas_Textblock_Style *ts, const char *text)
7358 /* Break if we found the tag end */ 7360 /* Break if we found the tag end */
7359 if (p[-1] != '\\') 7361 if (p[-1] != '\\')
7360 { 7362 {
7361 eina_strbuf_append_length(buf, val_stop, 7363 eina_strbuf_append_length(tag_value_buf, val_stop,
7362 p - val_stop); 7364 p - val_stop);
7363 break; 7365 break;
7364 } 7366 }
7365 else 7367 else
7366 { 7368 {
7367 eina_strbuf_append_length(buf, val_stop, 7369 eina_strbuf_append_length(tag_value_buf, val_stop,
7368 p - val_stop - 1); 7370 p - val_stop - 1);
7369 eina_strbuf_append_char(buf, '\''); 7371 eina_strbuf_append_char(tag_value_buf, '\'');
7370 val_stop = p + 1; 7372 val_stop = p + 1;
7371 } 7373 }
7372 } 7374 }
7373 p++; 7375 p++;
7374 } 7376 }
7375 replaces = eina_strbuf_string_steal(buf);
7376 eina_strbuf_free(buf);
7377 } 7377 }
7378 /* If we didn't find an end, just aboart. */ 7378 /* If we didn't find an end, just aboart. */
7379 if (!*p) 7379 if (!*p)
7380 { 7380 {
7381 if (replaces) free(replaces);
7382 break; 7381 break;
7383 } 7382 }
7384 7383
7385 tag_len = key_stop - key_start; 7384 tag_len = key_stop - key_start;
7386 7385
7387 tags = malloc(tag_len + 1); 7386 tag_value = eina_strbuf_string_get(tag_value_buf);
7388 if (tags) 7387 if (tag_len && (tag_value))
7389 { 7388 {
7390 memcpy(tags, key_start, tag_len); 7389 if (!strncmp(key_start, "DEFAULT", tag_len))
7391 tags[tag_len] = 0;
7392 }
7393
7394 if ((tags) && (replaces))
7395 {
7396 if (!strcmp(tags, "DEFAULT"))
7397 { 7390 {
7398 ts->default_tag = replaces; 7391 ts->default_tag = eina_stringshare_add(tag_value);
7399 free(tags);
7400 } 7392 }
7401 else 7393 else
7402 { 7394 {
7403 tag = calloc(1, sizeof(Evas_Object_Style_Tag)); 7395 tag = calloc(1, sizeof(Evas_Object_Style_Tag));
7404 if (tag) 7396 if (tag)
7405 { 7397 {
7406 tag->tag.tag = tags; 7398 tag->tag.tag = eina_stringshare_add_length(key_start, tag_len);
7407 tag->tag.replace = replaces; 7399 tag->tag.replace = eina_stringshare_add(tag_value);
7408 tag->tag.tag_len = tag_len; 7400 tag->tag.tag_len = tag_len;
7409 ts->tags = (Evas_Object_Style_Tag *)eina_inlist_append(EINA_INLIST_GET(ts->tags), EINA_INLIST_GET(tag)); 7401 ts->tags = (Evas_Object_Style_Tag *)eina_inlist_append(EINA_INLIST_GET(ts->tags), EINA_INLIST_GET(tag));
7410 } 7402 }
7411 else
7412 {
7413 free(tags);
7414 free(replaces);
7415 }
7416 } 7403 }
7417 } 7404 }
7418 else
7419 {
7420 if (tags) free(tags);
7421 if (replaces) free(replaces);
7422 }
7423 key_start = key_stop = val_start = NULL; 7405 key_start = key_stop = val_start = NULL;
7424 } 7406 }
7425 p++; 7407 p++;
7426 } 7408 }
7409 eina_strbuf_free(tag_value_buf);
7427 } 7410 }
7428 7411
7429 EINA_LIST_FOREACH(ts->objects, l, eo_obj) 7412 EINA_LIST_FOREACH(ts->objects, l, eo_obj)