summaryrefslogtreecommitdiff
path: root/legacy
diff options
context:
space:
mode:
authorCedric BAIL <cedric.bail@free.fr>2012-08-09 08:27:04 +0000
committerCedric BAIL <cedric.bail@free.fr>2012-08-09 08:27:04 +0000
commit40bfd3933f0cbf642d7ef6f436957a513e63e3d8 (patch)
tree0fbeee88fdb1ebf7410a2e130e74fd66a90c2cf6 /legacy
parentee1517b58a045169327649277f3495d7564b0beb (diff)
edje: improve speed of color class lookup by using an Eina_Hash.
SVN revision: 75034
Diffstat (limited to 'legacy')
-rw-r--r--legacy/edje/ChangeLog4
-rw-r--r--legacy/edje/NEWS1
-rw-r--r--legacy/edje/src/lib/edje_cache.c6
-rw-r--r--legacy/edje/src/lib/edje_load.c1
-rw-r--r--legacy/edje/src/lib/edje_main.c6
-rw-r--r--legacy/edje/src/lib/edje_private.h4
-rw-r--r--legacy/edje/src/lib/edje_smart.c11
-rw-r--r--legacy/edje/src/lib/edje_util.c85
8 files changed, 62 insertions, 56 deletions
diff --git a/legacy/edje/ChangeLog b/legacy/edje/ChangeLog
index cd499375b1..28c7f364c9 100644
--- a/legacy/edje/ChangeLog
+++ b/legacy/edje/ChangeLog
@@ -548,3 +548,7 @@
5482012-08-07 Cedric Bail 5482012-08-07 Cedric Bail
549 549
550 * Fix memory leak when Edje file have alias defined. 550 * Fix memory leak when Edje file have alias defined.
551
5522012-08-09 Cedric Bail
553
554 * Improve speed of color_class lookup by using an Eina_Hash.
diff --git a/legacy/edje/NEWS b/legacy/edje/NEWS
index eac793e963..abd070be84 100644
--- a/legacy/edje/NEWS
+++ b/legacy/edje/NEWS
@@ -18,6 +18,7 @@ Improvements:
18 * Allocate once and reuse Evas_Map. 18 * Allocate once and reuse Evas_Map.
19 * Make edje_cc faster by improving the parser, mapping file in memory and using threads. 19 * Make edje_cc faster by improving the parser, mapping file in memory and using threads.
20 * Made state index optional in EDC files and Embryo scripts. 20 * Made state index optional in EDC files and Embryo scripts.
21 * Improve speed of color_class lookup by using an Eina_Hash.
21 22
22Fixes: 23Fixes:
23 * Add missing files in the tarballs. 24 * Add missing files in the tarballs.
diff --git a/legacy/edje/src/lib/edje_cache.c b/legacy/edje/src/lib/edje_cache.c
index 77095e63ae..303de703e1 100644
--- a/legacy/edje/src/lib/edje_cache.c
+++ b/legacy/edje/src/lib/edje_cache.c
@@ -173,7 +173,9 @@ _edje_file_change(void *data, int ev_type __UNUSED__, void *event)
173static Edje_File * 173static Edje_File *
174_edje_file_open(const char *file, const char *coll, int *error_ret, Edje_Part_Collection **edc_ret, time_t mtime) 174_edje_file_open(const char *file, const char *coll, int *error_ret, Edje_Part_Collection **edc_ret, time_t mtime)
175{ 175{
176 Edje_Color_Class *cc;
176 Edje_File *edf; 177 Edje_File *edf;
178 Eina_List *l;
177 Edje_Part_Collection *edc; 179 Edje_Part_Collection *edc;
178 Eet_File *ef; 180 Eet_File *ef;
179#ifdef HAVE_EIO 181#ifdef HAVE_EIO
@@ -231,6 +233,10 @@ _edje_file_open(const char *file, const char *coll, int *error_ret, Edje_Part_Co
231 233
232 /* This should be done at edje generation time */ 234 /* This should be done at edje generation time */
233 _edje_textblock_style_parse_and_fix(edf); 235 _edje_textblock_style_parse_and_fix(edf);
236 edf->color_hash = eina_hash_string_small_new(NULL);
237 EINA_LIST_FOREACH(edf->color_classes, l, cc)
238 if (cc->name)
239 eina_hash_direct_add(edf->color_hash, cc->name, cc);
234 240
235 if (coll) 241 if (coll)
236 { 242 {
diff --git a/legacy/edje/src/lib/edje_load.c b/legacy/edje/src/lib/edje_load.c
index c7ae973106..453db2cf24 100644
--- a/legacy/edje/src/lib/edje_load.c
+++ b/legacy/edje/src/lib/edje_load.c
@@ -1328,6 +1328,7 @@ _edje_file_free(Edje_File *edf)
1328 free(edf->external_dir); 1328 free(edf->external_dir);
1329 } 1329 }
1330 1330
1331 eina_hash_free(edf->color_hash);
1331 EINA_LIST_FREE(edf->color_classes, ecc) 1332 EINA_LIST_FREE(edf->color_classes, ecc)
1332 { 1333 {
1333 if (edf->free_strings && ecc->name) eina_stringshare_del(ecc->name); 1334 if (edf->free_strings && ecc->name) eina_stringshare_del(ecc->name);
diff --git a/legacy/edje/src/lib/edje_main.c b/legacy/edje/src/lib/edje_main.c
index 56cf823993..0ae408d4a3 100644
--- a/legacy/edje/src/lib/edje_main.c
+++ b/legacy/edje/src/lib/edje_main.c
@@ -237,11 +237,7 @@ _edje_del(Edje *ed)
237 if (escb->source) eina_stringshare_del(escb->source); 237 if (escb->source) eina_stringshare_del(escb->source);
238 free(escb); 238 free(escb);
239 } 239 }
240 EINA_LIST_FREE(ed->color_classes, cc) 240 eina_hash_free(ed->color_classes);
241 {
242 if (cc->name) eina_stringshare_del(cc->name);
243 free(cc);
244 }
245 EINA_LIST_FREE(ed->text_classes, tc) 241 EINA_LIST_FREE(ed->text_classes, tc)
246 { 242 {
247 if (tc->name) eina_stringshare_del(tc->name); 243 if (tc->name) eina_stringshare_del(tc->name);
diff --git a/legacy/edje/src/lib/edje_private.h b/legacy/edje/src/lib/edje_private.h
index 3407b9c4e6..dabfbfb457 100644
--- a/legacy/edje/src/lib/edje_private.h
+++ b/legacy/edje/src/lib/edje_private.h
@@ -453,7 +453,9 @@ struct _Edje_File
453 Edje_Image_Directory *image_dir; 453 Edje_Image_Directory *image_dir;
454 Edje_Sound_Directory *sound_dir; 454 Edje_Sound_Directory *sound_dir;
455 Eina_List *styles; 455 Eina_List *styles;
456
456 Eina_List *color_classes; 457 Eina_List *color_classes;
458 Eina_Hash *color_hash;
457 459
458 int references; 460 int references;
459 const char *compiler; 461 const char *compiler;
@@ -1121,7 +1123,7 @@ struct _Edje
1121 Eina_List *actions; /* currently running actions */ 1123 Eina_List *actions; /* currently running actions */
1122 Eina_List *callbacks; 1124 Eina_List *callbacks;
1123 Eina_List *pending_actions; 1125 Eina_List *pending_actions;
1124 Eina_List *color_classes; 1126 Eina_Hash *color_classes;
1125 Eina_List *text_classes; 1127 Eina_List *text_classes;
1126 /* variable pool for Edje Embryo scripts */ 1128 /* variable pool for Edje Embryo scripts */
1127 Edje_Var_Pool *var_pool; 1129 Edje_Var_Pool *var_pool;
diff --git a/legacy/edje/src/lib/edje_smart.c b/legacy/edje/src/lib/edje_smart.c
index 2c74c509c6..0a855cfa1d 100644
--- a/legacy/edje/src/lib/edje_smart.c
+++ b/legacy/edje/src/lib/edje_smart.c
@@ -77,6 +77,16 @@ _edje_object_smart_class_get(void)
77 return class; 77 return class;
78} 78}
79 79
80static void
81_edje_color_class_free(void *data)
82{
83 Edje_Color_Class *cc = data;
84
85 if (cc->name) eina_stringshare_del(cc->name);
86 free(cc);
87}
88
89
80/* Private Routines */ 90/* Private Routines */
81static void 91static void
82_edje_smart_add(Evas_Object *obj) 92_edje_smart_add(Evas_Object *obj)
@@ -113,6 +123,7 @@ _edje_smart_add(Evas_Object *obj)
113 ed->have_objects = 1; 123 ed->have_objects = 1;
114 ed->references = 1; 124 ed->references = 1;
115 ed->user_defined = NULL; 125 ed->user_defined = NULL;
126 ed->color_classes = eina_hash_string_small_new(_edje_color_class_free);
116 127
117 evas_object_geometry_get(obj, &(ed->x), &(ed->y), &(ed->w), &(ed->h)); 128 evas_object_geometry_get(obj, &(ed->x), &(ed->y), &(ed->w), &(ed->h));
118 ed->obj = obj; 129 ed->obj = obj;
diff --git a/legacy/edje/src/lib/edje_util.c b/legacy/edje/src/lib/edje_util.c
index d207eca865..c684e37a42 100644
--- a/legacy/edje/src/lib/edje_util.c
+++ b/legacy/edje/src/lib/edje_util.c
@@ -627,7 +627,6 @@ EAPI Eina_Bool
627edje_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) 627edje_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)
628{ 628{
629 Edje *ed; 629 Edje *ed;
630 Eina_List *l;
631 Edje_Color_Class *cc; 630 Edje_Color_Class *cc;
632 unsigned int i; 631 unsigned int i;
633 632
@@ -641,42 +640,39 @@ edje_object_color_class_set(Evas_Object *obj, const char *color_class, int r, in
641 else if (b > 255) b = 255; 640 else if (b > 255) b = 255;
642 if (a < 0) a = 0; 641 if (a < 0) a = 0;
643 else if (a > 255) a = 255; 642 else if (a > 255) a = 255;
644 color_class = eina_stringshare_add(color_class); 643 cc = eina_hash_find(ed->color_classes, color_class);
645 if (!color_class) return EINA_FALSE; 644 if (cc)
646 EINA_LIST_FOREACH(ed->color_classes, l, cc)
647 { 645 {
648 if (cc->name == color_class) 646 if ((cc->r == r) && (cc->g == g) &&
649 { 647 (cc->b == b) && (cc->a == a) &&
650 eina_stringshare_del(color_class); 648 (cc->r2 == r2) && (cc->g2 == g2) &&
651 649 (cc->b2 == b2) && (cc->a2 == a2) &&
652 if ((cc->r == r) && (cc->g == g) && 650 (cc->r3 == r3) && (cc->g3 == g3) &&
653 (cc->b == b) && (cc->a == a) && 651 (cc->b3 == b3) && (cc->a3 == a3))
654 (cc->r2 == r2) && (cc->g2 == g2) && 652 return EINA_TRUE;
655 (cc->b2 == b2) && (cc->a2 == a2) && 653 cc->r = r;
656 (cc->r3 == r3) && (cc->g3 == g3) && 654 cc->g = g;
657 (cc->b3 == b3) && (cc->a3 == a3)) 655 cc->b = b;
658 return EINA_TRUE; 656 cc->a = a;
659 cc->r = r; 657 cc->r2 = r2;
660 cc->g = g; 658 cc->g2 = g2;
661 cc->b = b; 659 cc->b2 = b2;
662 cc->a = a; 660 cc->a2 = a2;
663 cc->r2 = r2; 661 cc->r3 = r3;
664 cc->g2 = g2; 662 cc->g3 = g3;
665 cc->b2 = b2; 663 cc->b3 = b3;
666 cc->a2 = a2; 664 cc->a3 = a3;
667 cc->r3 = r3; 665 ed->dirty = 1;
668 cc->g3 = g3; 666 ed->recalc_call = 1;
669 cc->b3 = b3;
670 cc->a3 = a3;
671 ed->dirty = 1;
672 ed->recalc_call = 1;
673#ifdef EDJE_CALC_CACHE 667#ifdef EDJE_CALC_CACHE
674 ed->all_part_change = 1; 668 ed->all_part_change = 1;
675#endif 669#endif
676 _edje_recalc(ed); 670 _edje_recalc(ed);
677 return EINA_TRUE; 671 return EINA_TRUE;
678 }
679 } 672 }
673
674 color_class = eina_stringshare_add(color_class);
675 if (!color_class) return EINA_FALSE;
680 cc = malloc(sizeof(Edje_Color_Class)); 676 cc = malloc(sizeof(Edje_Color_Class));
681 if (!cc) 677 if (!cc)
682 { 678 {
@@ -696,7 +692,7 @@ edje_object_color_class_set(Evas_Object *obj, const char *color_class, int r, in
696 cc->g3 = g3; 692 cc->g3 = g3;
697 cc->b3 = b3; 693 cc->b3 = b3;
698 cc->a3 = a3; 694 cc->a3 = a3;
699 ed->color_classes = eina_list_append(ed->color_classes, cc); 695 eina_hash_direct_add(ed->color_classes, cc->name, cc);
700 ed->dirty = 1; 696 ed->dirty = 1;
701 ed->recalc_call = 1; 697 ed->recalc_call = 1;
702#ifdef EDJE_CALC_CACHE 698#ifdef EDJE_CALC_CACHE
@@ -753,7 +749,6 @@ void
753edje_object_color_class_del(Evas_Object *obj, const char *color_class) 749edje_object_color_class_del(Evas_Object *obj, const char *color_class)
754{ 750{
755 Edje *ed; 751 Edje *ed;
756 Eina_List *l;
757 Edje_Color_Class *cc = NULL; 752 Edje_Color_Class *cc = NULL;
758 unsigned int i; 753 unsigned int i;
759 754
@@ -761,16 +756,7 @@ edje_object_color_class_del(Evas_Object *obj, const char *color_class)
761 756
762 if ((!ed) || (!color_class)) return; 757 if ((!ed) || (!color_class)) return;
763 758
764 EINA_LIST_FOREACH(ed->color_classes, l, cc) 759 eina_hash_del(ed->color_classes, color_class, cc);
765 {
766 if (!strcmp(cc->name, color_class))
767 {
768 ed->color_classes = eina_list_remove(ed->color_classes, cc);
769 eina_stringshare_del(cc->name);
770 free(cc);
771 break;
772 }
773 }
774 760
775 for (i = 0; i < ed->table_parts_size; i++) 761 for (i = 0; i < ed->table_parts_size; i++)
776 { 762 {
@@ -4712,22 +4698,21 @@ _edje_real_part_get(const Edje *ed, const char *part)
4712Edje_Color_Class * 4698Edje_Color_Class *
4713_edje_color_class_find(Edje *ed, const char *color_class) 4699_edje_color_class_find(Edje *ed, const char *color_class)
4714{ 4700{
4715 Eina_List *l;
4716 Edje_Color_Class *cc = NULL; 4701 Edje_Color_Class *cc = NULL;
4717 4702
4718 if ((!ed) || (!color_class)) return NULL; 4703 if ((!ed) || (!color_class)) return NULL;
4719 4704
4720 /* first look through the object scope */ 4705 /* first look through the object scope */
4721 EINA_LIST_FOREACH(ed->color_classes, l, cc) 4706 cc = eina_hash_find(ed->color_classes, color_class);
4722 if ((cc->name) && (!strcmp(color_class, cc->name))) return cc; 4707 if (cc) return cc;
4723 4708
4724 /* next look through the global scope */ 4709 /* next look through the global scope */
4725 cc = eina_hash_find(_edje_color_class_hash, color_class); 4710 cc = eina_hash_find(_edje_color_class_hash, color_class);
4726 if (cc) return cc; 4711 if (cc) return cc;
4727 4712
4728 /* finally, look through the file scope */ 4713 /* finally, look through the file scope */
4729 EINA_LIST_FOREACH(ed->file->color_classes, l, cc) 4714 cc = eina_hash_find(ed->file->color_hash, color_class);
4730 if ((cc->name) && (!strcmp(color_class, cc->name))) return cc; 4715 if (cc) return cc;
4731 4716
4732 return NULL; 4717 return NULL;
4733} 4718}