summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsubhransu mohanty <sub.mohanty@samsung.com>2019-08-26 08:08:29 -0400
committerMike Blumenkrantz <zmike@samsung.com>2019-08-26 08:31:08 -0400
commit02b63b8260063d5185f82affd587874b2d49e8f9 (patch)
tree3197bb8a6b791a610932513b12ffc8b11315b4bf
parent5bd95c9850df0fa914dde04761065515b9d3f7e4 (diff)
downloadefl-02b63b8260063d5185f82affd587874b2d49e8f9.tar.gz
edje/cache: Refactor _edje_cache_file_coll_open()
Summary: This function does lot of things - can be called only to load the file (by passing coll as null) - can be called to load both file and open the collection from the file. - handles the file_cache logic - handles fixing the collection after reading from file. this patch is targeting to split the responsibility to smaller function for easy maintenance and code readability. future patch to follow for splitting the file opening and collection opening to two different function. Reviewers: Hermet, raster, cedric, zmike Reviewed By: zmike Subscribers: zmike, cedric, #reviewers, #committers Tags: #efl Differential Revision: https://phab.enlightenment.org/D9715
-rw-r--r--src/lib/edje/edje_cache.c270
1 files changed, 150 insertions, 120 deletions
diff --git a/src/lib/edje/edje_cache.c b/src/lib/edje/edje_cache.c
index c1d39f7543..986ee71ab9 100644
--- a/src/lib/edje/edje_cache.c
+++ b/src/lib/edje/edje_cache.c
@@ -156,6 +156,103 @@ _edje_programs_patterns_init(Edje_Part_Collection *edc)
ssp->sources_patterns = edje_match_programs_source_init(all, j);
}
+static inline void
+_edje_part_collection_fix(Edje_Part_Collection *edc)
+{
+ if (edc->checked) return;
+
+ edc->checked = 1;
+
+ unsigned int j;
+ Edje_Part *ep;
+ Eina_List *hist;
+
+ for (j = 0; j < edc->parts_count; ++j)
+ {
+ Edje_Part *ep2;
+ ep = edc->parts[j];
+
+ /* Register any color classes in this parts descriptions. */
+ hist = NULL;
+ hist = eina_list_append(hist, ep);
+ ep2 = ep;
+ while (ep2->dragable.confine_id >= 0)
+ {
+ if (ep2->dragable.confine_id >= (int)edc->parts_count)
+ {
+ ERR("confine_to above limit. invalidating it.");
+ ep2->dragable.confine_id = -1;
+ break;
+ }
+
+ ep2 = edc->parts[ep2->dragable.confine_id];
+ if (eina_list_data_find(hist, ep2))
+ {
+ ERR("confine_to loops. invalidating loop.");
+ ep2->dragable.confine_id = -1;
+ break;
+ }
+ hist = eina_list_append(hist, ep2);
+ }
+ eina_list_free(hist);
+ hist = NULL;
+ hist = eina_list_append(hist, ep);
+ ep2 = ep;
+ while (ep2->dragable.event_id >= 0)
+ {
+ Edje_Part *prev;
+
+ if (ep2->dragable.event_id >= (int)edc->parts_count)
+ {
+ ERR("event_id above limit. invalidating it.");
+ ep2->dragable.event_id = -1;
+ break;
+ }
+ prev = ep2;
+
+ ep2 = edc->parts[ep2->dragable.event_id];
+ /* events_to may be used only with dragable */
+ if (!ep2->dragable.x && !ep2->dragable.y)
+ {
+ prev->dragable.event_id = -1;
+ break;
+ }
+
+ if (eina_list_data_find(hist, ep2))
+ {
+ ERR("events_to loops. invalidating loop.");
+ ep2->dragable.event_id = -1;
+ break;
+ }
+ hist = eina_list_append(hist, ep2);
+ }
+ eina_list_free(hist);
+ hist = NULL;
+ hist = eina_list_append(hist, ep);
+ ep2 = ep;
+ while (ep2->clip_to_id >= 0)
+ {
+ if (ep2->clip_to_id >= (int)edc->parts_count)
+ {
+ ERR("clip_to_id above limit. invalidating it.");
+ ep2->clip_to_id = -1;
+ break;
+ }
+
+ ep2 = edc->parts[ep2->clip_to_id];
+ if (eina_list_data_find(hist, ep2))
+ {
+ ERR("clip_to loops. invalidating loop.");
+ ep2->clip_to_id = -1;
+ break;
+ }
+ hist = eina_list_append(hist, ep2);
+ }
+ eina_list_free(hist);
+ hist = NULL;
+ }
+}
+
static Edje_Part_Collection *
_edje_file_coll_open(Edje_File *edf, const char *coll)
{
@@ -284,6 +381,8 @@ _edje_file_coll_open(Edje_File *edf, const char *coll)
}
}
+ _edje_part_collection_fix(edc);
+
return edc;
}
@@ -463,30 +562,21 @@ _edje_file_dangling(Edje_File *edf)
#endif
-Edje_File *
-_edje_cache_file_coll_open(const Eina_File *file, const char *coll, int *error_ret, Edje_Part_Collection **edc_ret, Edje *ed EINA_UNUSED)
+static inline void
+_edje_file_cache_init()
{
- Edje_File *edf;
- Eina_List *l, *hist;
- Edje_Part_Collection *edc;
- Edje_Part *ep;
-
if (!_edje_id_hash)
_edje_id_hash = eina_hash_stringshared_new(NULL);
if (!_edje_file_hash)
- {
- _edje_file_hash = eina_hash_pointer_new(NULL);
- goto find_list;
- }
+ _edje_file_hash = eina_hash_pointer_new(NULL);
+}
- edf = eina_hash_find(_edje_file_hash, &file);
- if (edf)
- {
- edf->references++;
- goto open;
- }
+static inline Edje_File*
+_edje_file_cache_trash_pop(const Eina_File *file)
+{
+ Edje_File *edf;
+ Eina_List *l;
-find_list:
EINA_LIST_FOREACH(_edje_file_cache, l, edf)
{
if (edf->f == file)
@@ -494,121 +584,61 @@ find_list:
edf->references = 1;
_edje_file_cache = eina_list_remove_list(_edje_file_cache, l);
eina_hash_direct_add(_edje_file_hash, &edf->f, edf);
- goto open;
+ return edf;
}
}
+ return NULL;
+}
+
+static inline Edje_File*
+_edje_file_cache_find(const Eina_File *file)
+{
+ Edje_File *edf;
+
+ // initialize cache.
+ _edje_file_cache_init();
+
+ // serach in the file_hash.
+ edf = eina_hash_find(_edje_file_hash, &file);
+ if (edf)
+ {
+ edf->references++;
+ return edf;
+ }
- edf = _edje_file_open(file, error_ret, eina_file_mtime_get(file), !!coll);
- if (!edf) return NULL;
+ // search in the trash list
+ return _edje_file_cache_trash_pop(file);
+}
+static inline void
+_edje_file_cache_add(Edje_File *edf)
+{
eina_hash_direct_add(_edje_file_hash, &edf->f, edf);
if (edf->id)
eina_hash_list_append(_edje_id_hash, edf->id, edf);
- /* return edf; */
+}
-open:
- if (!coll)
- return edf;
+Edje_File *
+_edje_cache_file_coll_open(const Eina_File *file, const char *coll, int *error_ret, Edje_Part_Collection **edc_ret, Edje *ed EINA_UNUSED)
+{
+ Edje_File *edf;
+ Edje_Part_Collection *edc;
- edc = _edje_file_coll_open(edf, coll);
- if (!edc)
+ edf = _edje_file_cache_find(file);
+
+ if (!edf)
{
- *error_ret = EDJE_LOAD_ERROR_UNKNOWN_COLLECTION;
+ edf = _edje_file_open(file, error_ret, eina_file_mtime_get(file), !!coll);
+ if (!edf) return NULL;
+ _edje_file_cache_add(edf);
}
- else
- {
- if (!edc->checked)
- {
- unsigned int j;
-
- for (j = 0; j < edc->parts_count; ++j)
- {
- Edje_Part *ep2;
- ep = edc->parts[j];
+ if (!coll)
+ return edf;
- /* Register any color classes in this parts descriptions. */
- hist = NULL;
- hist = eina_list_append(hist, ep);
- ep2 = ep;
- while (ep2->dragable.confine_id >= 0)
- {
- if (ep2->dragable.confine_id >= (int)edc->parts_count)
- {
- ERR("confine_to above limit. invalidating it.");
- ep2->dragable.confine_id = -1;
- break;
- }
-
- ep2 = edc->parts[ep2->dragable.confine_id];
- if (eina_list_data_find(hist, ep2))
- {
- ERR("confine_to loops. invalidating loop.");
- ep2->dragable.confine_id = -1;
- break;
- }
- hist = eina_list_append(hist, ep2);
- }
- eina_list_free(hist);
- hist = NULL;
- hist = eina_list_append(hist, ep);
- ep2 = ep;
- while (ep2->dragable.event_id >= 0)
- {
- Edje_Part *prev;
-
- if (ep2->dragable.event_id >= (int)edc->parts_count)
- {
- ERR("event_id above limit. invalidating it.");
- ep2->dragable.event_id = -1;
- break;
- }
- prev = ep2;
-
- ep2 = edc->parts[ep2->dragable.event_id];
- /* events_to may be used only with dragable */
- if (!ep2->dragable.x && !ep2->dragable.y)
- {
- prev->dragable.event_id = -1;
- break;
- }
-
- if (eina_list_data_find(hist, ep2))
- {
- ERR("events_to loops. invalidating loop.");
- ep2->dragable.event_id = -1;
- break;
- }
- hist = eina_list_append(hist, ep2);
- }
- eina_list_free(hist);
- hist = NULL;
- hist = eina_list_append(hist, ep);
- ep2 = ep;
- while (ep2->clip_to_id >= 0)
- {
- if (ep2->clip_to_id >= (int)edc->parts_count)
- {
- ERR("clip_to_id above limit. invalidating it.");
- ep2->clip_to_id = -1;
- break;
- }
-
- ep2 = edc->parts[ep2->clip_to_id];
- if (eina_list_data_find(hist, ep2))
- {
- ERR("clip_to loops. invalidating loop.");
- ep2->clip_to_id = -1;
- break;
- }
- hist = eina_list_append(hist, ep2);
- }
- eina_list_free(hist);
- hist = NULL;
- }
- edc->checked = 1;
- }
- }
+ edc = _edje_file_coll_open(edf, coll);
+ if (!edc)
+ *error_ret = EDJE_LOAD_ERROR_UNKNOWN_COLLECTION;
if (edc_ret) *edc_ret = edc;