edje: improve speed of color class lookup by using an Eina_Hash.

SVN revision: 75034
This commit is contained in:
Cedric BAIL 2012-08-09 08:27:04 +00:00
parent ee1517b58a
commit 40bfd3933f
8 changed files with 64 additions and 58 deletions

View File

@ -548,3 +548,7 @@
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.

View File

@ -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.

View 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)
{

View 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);

View 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);

View 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;

View 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;

View 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;
cc = eina_hash_find(ed->color_classes, color_class);
if (cc)
{
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;
#endif
_edje_recalc(ed);
return EINA_TRUE;
}
color_class = eina_stringshare_add(color_class);
if (!color_class) return EINA_FALSE;
EINA_LIST_FOREACH(ed->color_classes, l, 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;
#ifdef EDJE_CALC_CACHE
ed->all_part_change = 1;
#endif
_edje_recalc(ed);
return EINA_TRUE;
}
}
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;
}