edje/optimization: keep a style hash for fast retrival of styles
authorsubhransu mohanty <sub.mohanty@samsung.com>
Mon, 12 Aug 2019 23:18:39 +0000 (23:18 +0000)
committerWonki Kim <wonki_.kim@samsung.com>
Wed, 21 Aug 2019 02:01:32 +0000 (11:01 +0900)
As edje mostly deals with style string. to get the style data each time
it linearly search through list to find out the style which is not very
cache friendly so keep a hash to do first lookup with less impact on cache.

Reviewed-by: Cedric BAIL <cedric.bail@free.fr>
Differential Revision: https://phab.enlightenment.org/D9547

Change-Id: Iaea70dd61e54e85b83ac75a073f4ea2951f8dee7

src/lib/edje/edje_cache.c
src/lib/edje/edje_load.c
src/lib/edje/edje_private.h
src/lib/edje/edje_textblock_styles.c

index 2151a5d..abd73c0 100644 (file)
@@ -302,6 +302,7 @@ _edje_file_open(const Eina_File *f, int *error_ret, time_t mtime, Eina_Bool coll
    Edje_Color_Class *cc;
    Edje_Text_Class *tc;
    Edje_Size_Class *sc;
+   Edje_Style      *stl;
    Edje_File *edf;
    Eina_List *l, *ll;
    Eet_File *ef;
@@ -380,6 +381,11 @@ _edje_file_open(const Eina_File *f, int *error_ret, time_t mtime, Eina_Bool coll
    /* This should be done at edje generation time */
    _edje_textblock_style_parse_and_fix(edf);
 
+   edf->style_hash = eina_hash_string_small_new(NULL);
+   EINA_LIST_FOREACH(edf->styles, l, stl)
+     if (stl->name)
+       eina_hash_direct_add(edf->style_hash, stl->name, stl);
+
    edf->color_tree_hash = eina_hash_string_small_new(NULL);
    EINA_LIST_FOREACH(edf->color_tree, l, ctn)
      EINA_LIST_FOREACH(ctn->color_classes, ll, name)
index 497f409..3dda3fb 100644 (file)
@@ -2460,6 +2460,7 @@ _edje_file_free(Edje_File *edf)
    if (edf->path) eina_stringshare_del(edf->path);
    if (edf->free_strings && edf->compiler) eina_stringshare_del(edf->compiler);
    if (edf->free_strings) eina_stringshare_del(edf->id);
+   eina_hash_free(edf->style_hash);
    _edje_textblock_style_cleanup(edf);
    if (edf->ef) eet_close(edf->ef);
    if (edf->f) eina_file_close(edf->f);
index 4cf41ee..1fcbdf3 100644 (file)
@@ -563,6 +563,8 @@ struct _Edje_File
    Edje_Gfx_Filter_Directory      *filter_dir;
 
    Eina_List                      *styles;
+   Eina_Hash                      *style_hash;
+
    // TIZEN_ONLY(20150110): Add plugin keyword.
 #ifdef EDJE_TIZEN_PLUGIN
    Eina_List                      *plugins;
index 98f0659..3e3901e 100644 (file)
@@ -542,19 +542,9 @@ _edje_textblock_style_all_update(Edje *ed, Eina_Bool force)
 static inline Edje_Style *
 _edje_textblock_style_search(Edje *ed, const char *style)
 {
-   Edje_Style *stl = NULL;
-   Eina_List *l;
-
    if (!style) return NULL;
 
-   EINA_LIST_FOREACH(ed->file->styles, l, stl)
-     {
-        if ((stl->name) &&
-            (stl->name == style || !strcmp(stl->name, style))) break;
-        stl = NULL;
-     }
-
-   return stl;
+   return eina_hash_find(ed->file->style_hash, style);
 }
 
 static inline void
@@ -645,16 +635,9 @@ _edje_textblock_styles_del(Edje *ed, Edje_Part *pt)
 
    desc = (Edje_Part_Description_Text *)pt->default_desc;
    style = edje_string_get(&desc->text.style);
-   if (style)
-     {
-        Eina_List *l;
 
-        EINA_LIST_FOREACH(ed->file->styles, l, stl)
-          {
-             if ((stl->name) && (!strcmp(stl->name, style))) break;
-             stl = NULL;
-          }
-     }
+   stl = _edje_textblock_style_search(ed, style);
+
    if (stl)
      {
         Edje_Style_Tag *tag;
@@ -683,16 +666,7 @@ _edje_textblock_styles_del(Edje *ed, Edje_Part *pt)
      {
         desc = (Edje_Part_Description_Text *)pt->other.desc[i];
         style = edje_string_get(&desc->text.style);
-        if (style)
-          {
-             Eina_List *l;
-
-             EINA_LIST_FOREACH(ed->file->styles, l, stl)
-               {
-                  if ((stl->name) && (!strcmp(stl->name, style))) break;
-                  stl = NULL;
-               }
-          }
+        stl = _edje_textblock_style_search(ed, style);
         if (stl)
           {
              Edje_Style_Tag *tag;