raster pushed a commit to branch master.

http://git.enlightenment.org/core/elementary.git/commit/?id=8149176791a0245db9f501207e7a037f678924e2

commit 8149176791a0245db9f501207e7a037f678924e2
Author: Subhransu Sekhar Mohanty <[email protected]>
Date:   Tue Mar 18 17:18:09 2014 +0900

    elm_theme: Added a cache in elm_theme for styles that are failed to load.
    
    Summary:
    Currenlty loading a style that is not present in the system hits the worst 
case path in elm_theme as it searches through all hirarchy before
    reporting that the style is not there. if those styles requested frequently 
it will be a overhead as it will goes through all the theme files again.
    To avoid that I have added a cache which will keep track of the styles 
whose loading were not sucessfull so that for future request we can simply 
check the
    cache before looking into the hirarchy of theme files.
    
    Reviewers: seoz, raster
    
    Reviewed By: raster
    
    CC: raster
    
    Differential Revision: https://phab.enlightenment.org/D601
---
 src/lib/elm_priv.h  |  1 +
 src/lib/elm_theme.c | 54 +++++++++++++++++++++++++++++++++++------------------
 2 files changed, 37 insertions(+), 18 deletions(-)

diff --git a/src/lib/elm_priv.h b/src/lib/elm_priv.h
index 534b055..aa1f66a 100644
--- a/src/lib/elm_priv.h
+++ b/src/lib/elm_priv.h
@@ -112,6 +112,7 @@ struct _Elm_Theme
    Eina_List  *referrers;
    const char *theme;
    int         ref;
+   Eina_Hash  *cache_style_load_failed;
 };
 
 /* increment this whenever we change config enough that you need new
diff --git a/src/lib/elm_theme.c b/src/lib/elm_theme.c
index 28a5422..d6f47f0 100644
--- a/src/lib/elm_theme.c
+++ b/src/lib/elm_theme.c
@@ -9,7 +9,7 @@
 static Elm_Theme theme_default =
 {
   { NULL, NULL }, { NULL, NULL }, { NULL, NULL },
-  NULL, NULL, NULL, NULL, NULL, 1
+  NULL, NULL, NULL, NULL, NULL, 1, NULL
 };
 
 static Eina_List *themes = NULL;
@@ -169,6 +169,7 @@ _elm_theme_clear(Elm_Theme *th)
 
    ELM_SAFE_FREE(th->cache, eina_hash_free);
    ELM_SAFE_FREE(th->cache_data, eina_hash_free);
+   ELM_SAFE_FREE(th->cache_style_load_failed, eina_hash_free);
    ELM_SAFE_FREE(th->theme, eina_stringshare_del);
    if (th->ref_theme)
      {
@@ -328,29 +329,43 @@ _elm_theme_set(Elm_Theme *th, Evas_Object *o, const char 
*clas, const char *grou
    if (!th) th = &(theme_default);
 
    snprintf(buf2, sizeof(buf2), "elm/%s/%s/%s", clas, group, style);
-   file = _elm_theme_group_file_find(th, buf2);
-   if (file)
+   if (!eina_hash_find(th->cache_style_load_failed, buf2))
      {
-        if (edje_object_mmap_set(o, file, buf2)) return EINA_TRUE;
-        else
+        file = _elm_theme_group_file_find(th, buf2);
+        if (file)
           {
-             DBG("could not set theme group '%s' from file '%s': %s",
-                 buf2,
-                 eina_file_filename_get(file),
-                 edje_load_error_str(edje_object_load_error_get(o)));
+             if (edje_object_mmap_set(o, file, buf2)) return EINA_TRUE;
+             else
+               {
+                  DBG("could not set theme group '%s' from file '%s': %s",
+                      buf2,
+                      eina_file_filename_get(file),
+                      edje_load_error_str(edje_object_load_error_get(o)));
+               }
           }
+        //style not found, add to the not found list
+        eina_hash_add(th->cache_style_load_failed, buf2, (void *)1);
      }
 
    //Use the elementary default theme.
    snprintf(buf2, sizeof(buf2), "elm/%s/%s/default", clas, group);
-   file = _elm_theme_group_file_find(th, buf2);
-   if (!file) return EINA_FALSE;
-   if (edje_object_mmap_set(o, file, buf2)) return EINA_TRUE;
-   DBG("could not set theme group '%s' from file '%s': %s",
-       buf2,
-       eina_file_filename_get(file),
-       edje_load_error_str(edje_object_load_error_get(o)));
-
+   if (!eina_hash_find(th->cache_style_load_failed, buf2))
+     {
+        file = _elm_theme_group_file_find(th, buf2);
+        if (file)
+          {
+             if (edje_object_mmap_set(o, file, buf2)) return EINA_TRUE;
+             else
+               {
+                  DBG("could not set theme group '%s' from file '%s': %s",
+                      buf2,
+                      eina_file_filename_get(file),
+                      edje_load_error_str(edje_object_load_error_get(o)));
+               }
+          }
+        //style not found, add to the not found list
+        eina_hash_add(th->cache_style_load_failed, buf2, (void *)1);
+     }
    return EINA_FALSE;
 }
 
@@ -440,7 +455,8 @@ _elm_theme_parse(Elm_Theme *th, const char *theme)
    th->cache = eina_hash_string_superfast_new(EINA_FREE_CB(eina_file_close));
    if (th->cache_data) eina_hash_free(th->cache_data);
    th->cache_data = 
eina_hash_string_superfast_new(EINA_FREE_CB(eina_stringshare_del));
-
+   if (th->cache_style_load_failed) 
eina_hash_free(th->cache_style_load_failed);
+   th->cache_style_load_failed = eina_hash_string_superfast_new(NULL);
    EINA_LIST_FREE(th->themes.items, p) eina_stringshare_del(p);
    EINA_LIST_FREE(th->themes.handles, f) eina_file_close(f);
 
@@ -743,6 +759,8 @@ elm_theme_flush(Elm_Theme *th)
    th->cache = eina_hash_string_superfast_new(EINA_FREE_CB(eina_file_close));
    if (th->cache_data) eina_hash_free(th->cache_data);
    th->cache_data = 
eina_hash_string_superfast_new(EINA_FREE_CB(eina_stringshare_del));
+   if (th->cache_style_load_failed) 
eina_hash_free(th->cache_style_load_failed);
+   th->cache_style_load_failed = eina_hash_string_superfast_new(NULL);
    _elm_win_rescale(th, EINA_TRUE);
    _elm_ews_wm_rescale(th, EINA_TRUE);
    if (th->referrers)

-- 


Reply via email to