Evas textblock: Fix markup cache, was completely broken. 19/66919/2
authorTom Hacohen <tom@stosb.com>
Fri, 26 Feb 2016 09:06:00 +0000 (09:06 +0000)
committerYoungbok Shin <youngb.shin@samsung.com>
Mon, 25 Apr 2016 03:57:29 +0000 (20:57 -0700)
The markup cache was completely broken. It was not compared correctly,
so it wasn't even used, but regardless it was cleared just after being
set in some of the cases.

This is the first part of a performance regression fix in elm label.

@fix

Change-Id: I27e088c59b55aee5606b02ea021c386d8bde3a0d

src/lib/evas/canvas/evas_object_textblock.c

index ef9db67..ec1f85f 100644 (file)
@@ -521,7 +521,7 @@ struct _Evas_Object_Textblock
       int                              l, r, t, b;
    } style_pad;
    double                              valign;
-   char                               *markup_text;
+   Eina_Stringshare                   *markup_text;
    void                               *engine_data;
    const char                         *repch;
    const char                         *bidi_delimiters;
@@ -6496,7 +6496,7 @@ _textblock_style_generic_set(Evas_Object *eo_obj, Evas_Textblock_Style *ts,
         Evas_Textblock_Style *old_ts;
         if (o->markup_text)
           {
-             free(o->markup_text);
+             eina_stringshare_del(o->markup_text);
              o->markup_text = NULL;
           }
 
@@ -6854,10 +6854,14 @@ _evas_textblock_text_markup_set(Eo *eo_obj EINA_UNUSED, Evas_Textblock_Data *o,
 {
    Evas_Object_Protected_Data *obj = eo_data_scope_get(eo_obj, EVAS_OBJECT_CLASS);
    evas_object_async_block(obj);
-   if ((text != o->markup_text) && (o->markup_text))
+
      {
-        free(o->markup_text);
-        o->markup_text = NULL;
+        text = eina_stringshare_add(text);
+        if (text == o->markup_text)
+          {
+             /* Text is the same, do nothing. */
+             return;
+          }
      }
 
    _nodes_clear(eo_obj);
@@ -6867,15 +6871,6 @@ _evas_textblock_text_markup_set(Eo *eo_obj EINA_UNUSED, Evas_Textblock_Data *o,
             EINA_INLIST_GET(o->text_nodes),
             EINA_INLIST_GET(o->cursor->node)));
 
-   if (!o->style && !o->style_user)
-     {
-        if (text != o->markup_text)
-          {
-             if (text) o->markup_text = strdup(text);
-          }
-        return;
-     }
-
    evas_textblock_cursor_paragraph_first(o->cursor);
 
    evas_object_textblock_text_markup_prepend(o->cursor, text);
@@ -6888,6 +6883,8 @@ _evas_textblock_text_markup_set(Eo *eo_obj EINA_UNUSED, Evas_Textblock_Data *o,
         EINA_LIST_FOREACH(o->cursors, l, data)
            evas_textblock_cursor_paragraph_first(data);
      }
+
+    o->markup_text = text;
 }
 
 EAPI void
@@ -7176,7 +7173,7 @@ _evas_textblock_text_markup_get(Eo *eo_obj EINA_UNUSED, Evas_Textblock_Data *o)
         free(text_base);
      }
 
-   (((Evas_Textblock_Data *)o)->markup_text) = eina_strbuf_string_steal(txt);
+   (((Evas_Textblock_Data *)o)->markup_text) = eina_stringshare_add(eina_strbuf_string_get(txt));
    eina_strbuf_free(txt);
    markup = (o->markup_text);
 
@@ -9485,7 +9482,7 @@ _evas_textblock_changed(Evas_Textblock_Data *o, Evas_Object *eo_obj)
    o->content_changed = 1;
    if (o->markup_text)
      {
-        free(o->markup_text);
+        eina_stringshare_del(o->markup_text);
         o->markup_text = NULL;
      }