edje: improve speed of color class lookup by using an Eina_Hash.
authorcedric <cedric>
Thu, 9 Aug 2012 08:27:04 +0000 (08:27 +0000)
committercedric <cedric@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Thu, 9 Aug 2012 08:27:04 +0000 (08:27 +0000)
git-svn-id: http://svn.enlightenment.org/svn/e/trunk/edje@75034 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33

ChangeLog
NEWS
src/lib/edje_cache.c
src/lib/edje_load.c
src/lib/edje_main.c
src/lib/edje_private.h
src/lib/edje_smart.c
src/lib/edje_util.c

index cd49937..28c7f36 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
 2012-08-07  Cedric Bail
 
        * Fix memory leak when Edje file have alias defined.
+
+2012-08-09  Cedric Bail
+
+       * Improve speed of color_class lookup by using an Eina_Hash.
diff --git a/NEWS b/NEWS
index eac793e..abd070b 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -18,6 +18,7 @@ Improvements:
     * Allocate once and reuse Evas_Map.
     * Make edje_cc faster by improving the parser, mapping file in memory and using threads.
     * Made state index optional in EDC files and Embryo scripts.
+    * Improve speed of color_class lookup by using an Eina_Hash.
 
 Fixes:
     * Add missing files in the tarballs.
index 77095e6..303de70 100644 (file)
@@ -173,7 +173,9 @@ _edje_file_change(void *data, int ev_type __UNUSED__, void *event)
 static Edje_File *
 _edje_file_open(const char *file, const char *coll, int *error_ret, Edje_Part_Collection **edc_ret, time_t mtime)
 {
+   Edje_Color_Class *cc;
    Edje_File *edf;
+   Eina_List *l;
    Edje_Part_Collection *edc;
    Eet_File *ef;
 #ifdef HAVE_EIO
@@ -231,6 +233,10 @@ _edje_file_open(const char *file, const char *coll, int *error_ret, Edje_Part_Co
 
    /* This should be done at edje generation time */
    _edje_textblock_style_parse_and_fix(edf);
+   edf->color_hash = eina_hash_string_small_new(NULL);
+   EINA_LIST_FOREACH(edf->color_classes, l, cc)
+     if (cc->name)
+       eina_hash_direct_add(edf->color_hash, cc->name, cc);
 
    if (coll)
      {
index c7ae973..453db2c 100644 (file)
@@ -1328,6 +1328,7 @@ _edje_file_free(Edje_File *edf)
        free(edf->external_dir);
      }
 
+   eina_hash_free(edf->color_hash);
    EINA_LIST_FREE(edf->color_classes, ecc)
      {
        if (edf->free_strings && ecc->name) eina_stringshare_del(ecc->name);
index 56cf823..0ae408d 100644 (file)
@@ -237,11 +237,7 @@ _edje_del(Edje *ed)
        if (escb->source) eina_stringshare_del(escb->source);
        free(escb);
      }
-   EINA_LIST_FREE(ed->color_classes, cc)
-     {
-       if (cc->name) eina_stringshare_del(cc->name);
-       free(cc);
-     }
+   eina_hash_free(ed->color_classes);
    EINA_LIST_FREE(ed->text_classes, tc)
      {
        if (tc->name) eina_stringshare_del(tc->name);
index 3407b9c..dabfbfb 100644 (file)
@@ -453,7 +453,9 @@ struct _Edje_File
    Edje_Image_Directory           *image_dir;
    Edje_Sound_Directory           *sound_dir;
    Eina_List                      *styles;
+
    Eina_List                      *color_classes;
+   Eina_Hash                      *color_hash;
 
    int                             references;
    const char                     *compiler;
@@ -1121,7 +1123,7 @@ struct _Edje
    Eina_List            *actions; /* currently running actions */
    Eina_List            *callbacks;
    Eina_List            *pending_actions;
-   Eina_List            *color_classes;
+   Eina_Hash            *color_classes;
    Eina_List            *text_classes;
    /* variable pool for Edje Embryo scripts */
    Edje_Var_Pool        *var_pool;
index 2c74c50..0a855cf 100644 (file)
@@ -77,6 +77,16 @@ _edje_object_smart_class_get(void)
    return class;
 }
 
+static void
+_edje_color_class_free(void *data)
+{
+   Edje_Color_Class *cc = data;
+
+   if (cc->name) eina_stringshare_del(cc->name);
+   free(cc);
+}
+
+
 /* Private Routines */
 static void
 _edje_smart_add(Evas_Object *obj)
@@ -113,6 +123,7 @@ _edje_smart_add(Evas_Object *obj)
    ed->have_objects = 1;
    ed->references = 1;
    ed->user_defined = NULL;
+   ed->color_classes = eina_hash_string_small_new(_edje_color_class_free);
 
    evas_object_geometry_get(obj, &(ed->x), &(ed->y), &(ed->w), &(ed->h));
    ed->obj = obj;
index d207eca..c684e37 100644 (file)
@@ -627,7 +627,6 @@ EAPI Eina_Bool
 edje_object_color_class_set(Evas_Object *obj, const char *color_class, int r, int g, int b, int a, int r2, int g2, int b2, int a2, int r3, int g3, int b3, int a3)
 {
    Edje *ed;
-   Eina_List *l;
    Edje_Color_Class *cc;
    unsigned int i;
 
@@ -641,42 +640,39 @@ edje_object_color_class_set(Evas_Object *obj, const char *color_class, int r, in
    else if (b > 255) b = 255;
    if (a < 0)        a = 0;
    else if (a > 255) a = 255;
-   color_class = eina_stringshare_add(color_class);
-   if (!color_class) return EINA_FALSE;
-   EINA_LIST_FOREACH(ed->color_classes, l, cc)
+   cc = eina_hash_find(ed->color_classes, color_class);
+   if (cc)
      {
-       if (cc->name == color_class)
-         {
-            eina_stringshare_del(color_class);
-
-            if ((cc->r == r) && (cc->g == g) &&
-                (cc->b == b) && (cc->a == a) &&
-                (cc->r2 == r2) && (cc->g2 == g2) &&
-                (cc->b2 == b2) && (cc->a2 == a2) &&
-                (cc->r3 == r3) && (cc->g3 == g3) &&
-                (cc->b3 == b3) && (cc->a3 == a3))
-              return EINA_TRUE;
-            cc->r = r;
-            cc->g = g;
-            cc->b = b;
-            cc->a = a;
-            cc->r2 = r2;
-            cc->g2 = g2;
-            cc->b2 = b2;
-            cc->a2 = a2;
-            cc->r3 = r3;
-            cc->g3 = g3;
-            cc->b3 = b3;
-            cc->a3 = a3;
-            ed->dirty = 1;
-             ed->recalc_call = 1;
+       if ((cc->r == r) && (cc->g == g) &&
+          (cc->b == b) && (cc->a == a) &&
+          (cc->r2 == r2) && (cc->g2 == g2) &&
+          (cc->b2 == b2) && (cc->a2 == a2) &&
+          (cc->r3 == r3) && (cc->g3 == g3) &&
+          (cc->b3 == b3) && (cc->a3 == a3))
+        return EINA_TRUE;
+       cc->r = r;
+       cc->g = g;
+       cc->b = b;
+       cc->a = a;
+       cc->r2 = r2;
+       cc->g2 = g2;
+       cc->b2 = b2;
+       cc->a2 = a2;
+       cc->r3 = r3;
+       cc->g3 = g3;
+       cc->b3 = b3;
+       cc->a3 = a3;
+       ed->dirty = 1;
+       ed->recalc_call = 1;
 #ifdef EDJE_CALC_CACHE
-            ed->all_part_change = 1;
+       ed->all_part_change = 1;
 #endif
-            _edje_recalc(ed);
-            return EINA_TRUE;
-         }
+       _edje_recalc(ed);
+       return EINA_TRUE;
      }
+
+   color_class = eina_stringshare_add(color_class);
+   if (!color_class) return EINA_FALSE;
    cc = malloc(sizeof(Edje_Color_Class));
    if (!cc)
      {
@@ -696,7 +692,7 @@ edje_object_color_class_set(Evas_Object *obj, const char *color_class, int r, in
    cc->g3 = g3;
    cc->b3 = b3;
    cc->a3 = a3;
-   ed->color_classes = eina_list_append(ed->color_classes, cc);
+   eina_hash_direct_add(ed->color_classes, cc->name, cc);
    ed->dirty = 1;
    ed->recalc_call = 1;
 #ifdef EDJE_CALC_CACHE
@@ -753,7 +749,6 @@ void
 edje_object_color_class_del(Evas_Object *obj, const char *color_class)
 {
    Edje *ed;
-   Eina_List *l;
    Edje_Color_Class *cc = NULL;
    unsigned int i;
 
@@ -761,16 +756,7 @@ edje_object_color_class_del(Evas_Object *obj, const char *color_class)
 
    if ((!ed) || (!color_class)) return;
 
-   EINA_LIST_FOREACH(ed->color_classes, l, cc)
-     {
-       if (!strcmp(cc->name, color_class))
-         {
-            ed->color_classes = eina_list_remove(ed->color_classes, cc);
-            eina_stringshare_del(cc->name);
-            free(cc);
-            break;
-         }
-     }
+   eina_hash_del(ed->color_classes, color_class, cc);
 
    for (i = 0; i < ed->table_parts_size; i++)
      {
@@ -4712,22 +4698,21 @@ _edje_real_part_get(const Edje *ed, const char *part)
 Edje_Color_Class *
 _edje_color_class_find(Edje *ed, const char *color_class)
 {
-   Eina_List *l;
    Edje_Color_Class *cc = NULL;
 
    if ((!ed) || (!color_class)) return NULL;
 
    /* first look through the object scope */
-   EINA_LIST_FOREACH(ed->color_classes, l, cc)
-     if ((cc->name) && (!strcmp(color_class, cc->name))) return cc;
+   cc = eina_hash_find(ed->color_classes, color_class);
+   if (cc) return cc;
 
    /* next look through the global scope */
    cc = eina_hash_find(_edje_color_class_hash, color_class);
    if (cc) return cc;
 
    /* finally, look through the file scope */
-   EINA_LIST_FOREACH(ed->file->color_classes, l, cc)
-     if ((cc->name) && (!strcmp(color_class, cc->name))) return cc;
+   cc = eina_hash_find(ed->file->color_hash, color_class);
+   if (cc) return cc;
 
    return NULL;
 }