discomfitor pushed a commit to branch master. http://git.enlightenment.org/core/efl.git/commit/?id=fe0bd38f4cd0314ef41a151a894e6ec5413fdd97
commit fe0bd38f4cd0314ef41a151a894e6ec5413fdd97 Author: Mike Blumenkrantz <[email protected]> Date: Tue Feb 27 15:07:13 2018 -0500 elm_theme: massively simplify internals instead of maintaining separate lists for the file and the edje file, maintain a single list of structs containing both of these also dynamically manage a string list of files to preserve compat with existing (bad) functions which return this directly --- src/lib/elementary/elm_priv.h | 20 ++-- src/lib/elementary/elm_theme.c | 205 ++++++++++++++++++++++------------------- 2 files changed, 124 insertions(+), 101 deletions(-) diff --git a/src/lib/elementary/elm_priv.h b/src/lib/elementary/elm_priv.h index ec70ee4fbe..e6080d1319 100644 --- a/src/lib/elementary/elm_priv.h +++ b/src/lib/elementary/elm_priv.h @@ -116,21 +116,22 @@ struct _Edje_Signal_Data void *data; }; -struct _Elm_Theme_Files +typedef struct Elm_Theme_File { + EINA_INLIST; /* * We are conserving a list of path even if that's duplicated * because we expose those directly to the outside world :'( */ - Eina_List *items; - Eina_List *handles; -}; + Eina_Stringshare *item; + Eina_File *handle; +} Elm_Theme_File; struct _Elm_Theme { - Elm_Theme_Files overlay; - Elm_Theme_Files themes; - Elm_Theme_Files extension; + Eina_Inlist *overlay; + Eina_Inlist *themes; + Eina_Inlist *extension; Eina_Hash *cache; Eina_Hash *cache_data; @@ -139,6 +140,11 @@ struct _Elm_Theme const char *theme; int ref; Eina_Hash *cache_style_load_failed; + + /* these only exist to preserve compat with bad elm_theme_XYZ_list_get() api */ + Eina_List *overlay_items; + Eina_List *theme_items; + Eina_List *extension_items; }; /* increment this whenever we change config enough that you need new diff --git a/src/lib/elementary/elm_theme.c b/src/lib/elementary/elm_theme.c index 1a9d6a8184..f47c3217d9 100644 --- a/src/lib/elementary/elm_theme.c +++ b/src/lib/elementary/elm_theme.c @@ -9,7 +9,7 @@ static Elm_Theme theme_default = { - { NULL, NULL }, { NULL, NULL }, { NULL, NULL }, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 1, NULL }; @@ -27,12 +27,13 @@ _elm_theme_find_try(Elm_Theme *th, Eina_File *f, const char *group) } static inline void -_elm_theme_item_finalize(Elm_Theme_Files *files, +_elm_theme_item_finalize(Eina_Inlist **files, const char *item, Eina_File *f, Eina_Bool prepend, Eina_Bool istheme) { + Elm_Theme_File *etf; /* Theme version history: * <110: legacy, had no version tag * 110: first supported version @@ -55,22 +56,22 @@ _elm_theme_item_finalize(Elm_Theme_Files *files, } free(version); } + etf = calloc(1, sizeof(Elm_Theme_File)); + EINA_SAFETY_ON_NULL_RETURN(etf); + etf->item = eina_stringshare_add(item); + etf->handle = f; if (prepend) { - files->items = eina_list_prepend(files->items, - eina_stringshare_add(item)); - files->handles = eina_list_prepend(files->handles, f); + *files = eina_inlist_prepend(*files, EINA_INLIST_GET(etf)); } else { - files->items = eina_list_append(files->items, - eina_stringshare_add(item)); - files->handles = eina_list_append(files->handles, f); + *files = eina_inlist_append(*files, EINA_INLIST_GET(etf)); } } static void -_elm_theme_file_item_add(Elm_Theme_Files *files, const char *item, Eina_Bool prepend, Eina_Bool istheme) +_elm_theme_file_item_add(Eina_Inlist **files, const char *item, Eina_Bool prepend, Eina_Bool istheme) { Eina_Strbuf *buf = NULL; Eina_File *f = NULL; @@ -118,69 +119,53 @@ _elm_theme_file_item_add(Elm_Theme_Files *files, const char *item, Eina_Bool pre } static void -_elm_theme_file_item_del(Elm_Theme_Files *files, const char *str) +_elm_theme_file_item_del(Eina_Inlist **files, const char *str) { - Eina_List *l, *ll; - Eina_List *l2, *ll2; - const char *item; + Eina_Inlist *l; + Elm_Theme_File *item; str = eina_stringshare_add(str); - l2 = files->handles; - EINA_LIST_FOREACH_SAFE(files->items, l, ll, item) + EINA_INLIST_FOREACH_SAFE(*files, l, item) { - ll2 = l2->next; - - if (item == str) - { - eina_file_close(eina_list_data_get(l2)); - eina_stringshare_del(item); - - files->handles = eina_list_remove_list(files->handles, l2); - files->items = eina_list_remove_list(files->items, l); - } - - l2 = ll2; + if (item->item != str) continue; + eina_file_close(item->handle); + eina_stringshare_del(item->item); + *files = eina_inlist_remove(*files, EINA_INLIST_GET(item)); + free(item); } eina_stringshare_del(str); } static void -_elm_theme_file_mmap_del(Elm_Theme_Files *files, const Eina_File *file) +_elm_theme_file_mmap_del(Eina_Inlist **files, const Eina_File *file) { - Eina_List *l, *ll; - Eina_List *l2, *ll2; - Eina_File *f; + Eina_Inlist *l; + Elm_Theme_File *item; - l2 = files->items; - EINA_LIST_FOREACH_SAFE(files->handles, l, ll, f) + EINA_INLIST_FOREACH_SAFE(*files, l, item) { - ll2 = l2->next; - - if (f == file) - { - eina_file_close(f); - eina_stringshare_del(eina_list_data_get(l2)); - - files->handles = eina_list_remove_list(files->handles, l); - files->items = eina_list_remove_list(files->items, l2); - } - - l2 = ll2; + if (item->handle != file) continue; + eina_file_close(item->handle); + eina_stringshare_del(item->item); + *files = eina_inlist_remove(*files, EINA_INLIST_GET(item)); + free(item); } } static void -_elm_theme_file_clean(Elm_Theme_Files *files) +_elm_theme_file_clean(Eina_Inlist **files) { - const char *item; - Eina_File *f; + while (*files) + { + Elm_Theme_File *etf = EINA_INLIST_CONTAINER_GET(*files, Elm_Theme_File); - EINA_LIST_FREE(files->items, item) - eina_stringshare_del(item); - EINA_LIST_FREE(files->handles, f) - eina_file_close(f); + eina_stringshare_del(etf->item); + eina_file_close(etf->handle); + *files = eina_inlist_remove(*files, *files); + free(etf); + } } static void @@ -190,6 +175,10 @@ _elm_theme_clear(Elm_Theme *th) _elm_theme_file_clean(&th->overlay); _elm_theme_file_clean(&th->extension); + ELM_SAFE_FREE(th->overlay_items, eina_list_free); + ELM_SAFE_FREE(th->theme_items, eina_list_free); + ELM_SAFE_FREE(th->extension_items, eina_list_free); + 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); @@ -206,24 +195,24 @@ _elm_theme_clear(Elm_Theme *th) Eina_File * _elm_theme_group_file_find(Elm_Theme *th, const char *group) { - const Eina_List *l; + Elm_Theme_File *etf; Eina_File *file = eina_hash_find(th->cache, group); if (file) return file; - EINA_LIST_FOREACH(th->overlay.handles, l, file) + EINA_INLIST_FOREACH(th->overlay, etf) { - file = _elm_theme_find_try(th, file, group); + file = _elm_theme_find_try(th, etf->handle, group); if (file) return file; } - EINA_LIST_FOREACH(th->themes.handles, l, file) + EINA_INLIST_FOREACH(th->themes, etf) { - file = _elm_theme_find_try(th, file, group); + file = _elm_theme_find_try(th, etf->handle, group); if (file) return file; } - EINA_LIST_FOREACH(th->extension.handles, l, file) + EINA_INLIST_FOREACH(th->extension, etf) { - file = _elm_theme_find_try(th, file, group); + file = _elm_theme_find_try(th, etf->handle, group); if (file) return file; } if (th->ref_theme) return _elm_theme_group_file_find(th->ref_theme, group); @@ -250,25 +239,24 @@ _elm_theme_find_data_try(Elm_Theme *th, const Eina_File *f, const char *key) static const char * _elm_theme_data_find(Elm_Theme *th, const char *key) { - const Eina_List *l; - const Eina_File *f; + Elm_Theme_File *etf; const char *data = eina_hash_find(th->cache_data, key); if (data) return data; - EINA_LIST_FOREACH(th->overlay.handles, l, f) + EINA_INLIST_FOREACH(th->overlay, etf) { - data = _elm_theme_find_data_try(th, f, key); + data = _elm_theme_find_data_try(th, etf->handle, key); if (data) return data; } - EINA_LIST_FOREACH(th->themes.handles, l, f) + EINA_INLIST_FOREACH(th->overlay, etf) { - data = _elm_theme_find_data_try(th, f, key); + data = _elm_theme_find_data_try(th, etf->handle, key); if (data) return data; } - EINA_LIST_FOREACH(th->extension.handles, l, f) + EINA_INLIST_FOREACH(th->overlay, etf) { - data = _elm_theme_find_data_try(th, f, key); + data = _elm_theme_find_data_try(th, etf->handle, key); if (data) return data; } if (th->ref_theme) return _elm_theme_data_find(th->ref_theme, key); @@ -405,7 +393,6 @@ void _elm_theme_parse(Elm_Theme *th, const char *theme) { Eina_List *names = NULL; - Eina_File *f; const char *p, *pe; if (!th) th = &(theme_default); @@ -470,8 +457,8 @@ _elm_theme_parse(Elm_Theme *th, const char *theme) 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); + _elm_theme_file_clean(&th->themes); + th->theme_items = eina_list_free(th->theme_items); EINA_LIST_FREE(names, p) _elm_theme_file_item_add(&th->themes, p, EINA_FALSE, EINA_TRUE); @@ -515,18 +502,17 @@ elm_theme_free(Elm_Theme *th) } static void -elm_theme_files_copy(Elm_Theme_Files *dst, Elm_Theme_Files *src) +elm_theme_files_copy(Eina_Inlist **dst, Eina_Inlist **src) { - const Eina_List *l; - const Eina_File *f; - const char *item; + Elm_Theme_File *etf, *cpy; - EINA_LIST_FOREACH(src->items, l, item) - dst->items = eina_list_append(dst->items, - eina_stringshare_ref(item)); - EINA_LIST_FOREACH(src->handles, l, f) - dst->handles = eina_list_append(dst->handles, - eina_file_dup(f)); + EINA_INLIST_FOREACH(*src, etf) + { + cpy = malloc(sizeof(Elm_Theme_File)); + cpy->item = eina_stringshare_ref(etf->item); + cpy->handle = eina_file_dup(etf->handle); + *dst = eina_inlist_append(*dst, EINA_INLIST_GET(cpy)); + } } EAPI void @@ -584,6 +570,7 @@ elm_theme_overlay_add(Elm_Theme *th, const char *item) { if (!item) return; if (!th) th = &(theme_default); + th->overlay_items = eina_list_free(th->overlay_items); _elm_theme_file_item_add(&th->overlay, item, EINA_TRUE, EINA_FALSE); elm_theme_flush(th); } @@ -593,6 +580,7 @@ elm_theme_overlay_del(Elm_Theme *th, const char *item) { if (!item) return; if (!th) th = &(theme_default); + th->overlay_items = eina_list_free(th->overlay_items); _elm_theme_file_item_del(&th->overlay, item); elm_theme_flush(th); } @@ -603,6 +591,7 @@ elm_theme_overlay_mmap_add(Elm_Theme *th, const Eina_File *f) Eina_File *file = eina_file_dup(f); if (!th) th = &(theme_default); + th->overlay_items = eina_list_free(th->overlay_items); _elm_theme_item_finalize(&th->overlay, eina_file_filename_get(file), file, EINA_TRUE, EINA_FALSE); elm_theme_flush(th); } @@ -612,6 +601,7 @@ elm_theme_overlay_mmap_del(Elm_Theme *th, const Eina_File *f) { if (!f) return; if (!th) th = &(theme_default); + th->overlay_items = eina_list_free(th->overlay_items); _elm_theme_file_mmap_del(&th->overlay, f); elm_theme_flush(th); } @@ -620,7 +610,14 @@ EAPI const Eina_List * elm_theme_overlay_list_get(const Elm_Theme *th) { if (!th) th = &(theme_default); - return th->overlay.items; + if (!th->overlay_items) + { + Elm_Theme_File *etf; + + EINA_INLIST_FOREACH(th->overlay, etf) + ((Elm_Theme*)th)->overlay_items = eina_list_append(th->overlay_items, etf->item); + } + return th->overlay_items; } EAPI void @@ -628,6 +625,7 @@ elm_theme_extension_add(Elm_Theme *th, const char *item) { if (!item) return; if (!th) th = &(theme_default); + th->extension_items = eina_list_free(th->extension_items); _elm_theme_file_item_add(&th->extension, item, EINA_FALSE, EINA_FALSE); elm_theme_flush(th); } @@ -637,6 +635,7 @@ elm_theme_extension_del(Elm_Theme *th, const char *item) { if (!item) return; if (!th) th = &(theme_default); + th->extension_items = eina_list_free(th->extension_items); _elm_theme_file_item_del(&th->extension, item); elm_theme_flush(th); } @@ -648,6 +647,7 @@ elm_theme_extension_mmap_add(Elm_Theme *th, const Eina_File *f) if (!f) return; if (!th) th = &(theme_default); + th->extension_items = eina_list_free(th->extension_items); _elm_theme_item_finalize(&th->extension, eina_file_filename_get(file), file, EINA_FALSE, EINA_FALSE); elm_theme_flush(th); } @@ -657,6 +657,7 @@ elm_theme_extension_mmap_del(Elm_Theme *th, const Eina_File *f) { if (!f) return; if (!th) th = &(theme_default); + th->extension_items = eina_list_free(th->extension_items); _elm_theme_file_mmap_del(&th->extension, f); elm_theme_flush(th); } @@ -665,7 +666,14 @@ EAPI const Eina_List * elm_theme_extension_list_get(const Elm_Theme *th) { if (!th) th = &(theme_default); - return th->extension.items; + if (!th->extension_items) + { + Elm_Theme_File *etf; + + EINA_INLIST_FOREACH(th->extension, etf) + ((Elm_Theme*)th)->extension_items = eina_list_append(th->extension_items, etf->item); + } + return th->extension_items; } EAPI void @@ -686,12 +694,13 @@ elm_theme_get(Elm_Theme *th) if (!th->theme) { Eina_Strbuf *buf; - Eina_List *l; + Elm_Theme_File *etf; const char *f; buf = eina_strbuf_new(); - EINA_LIST_FOREACH(th->themes.items, l, f) + EINA_INLIST_FOREACH(th->themes, etf) { + f = etf->item; while (*f) { if (*f == ':') @@ -700,7 +709,8 @@ elm_theme_get(Elm_Theme *th) f++; } - if (l->next) eina_strbuf_append_char(buf, ':'); + if (EINA_INLIST_GET(etf)->next) + eina_strbuf_append_char(buf, ':'); } th->theme = eina_stringshare_add(eina_strbuf_string_get(buf)); eina_strbuf_free(buf); @@ -712,7 +722,14 @@ EAPI const Eina_List * elm_theme_list_get(const Elm_Theme *th) { if (!th) th = &(theme_default); - return th->themes.items; + if (!th->theme_items) + { + Elm_Theme_File *etf; + + EINA_INLIST_FOREACH(th->themes, etf) + ((Elm_Theme*)th)->theme_items = eina_list_append(th->theme_items, etf->item); + } + return th->theme_items; } EAPI char * @@ -906,17 +923,17 @@ elm_theme_group_path_find(Elm_Theme *th, const char *group) static Eina_List * _elm_theme_file_group_base_list(Eina_List *list, - Eina_List *handles, + Eina_Inlist *handles, const char *base, int len) { Eina_Stringshare *c, *c2; Eina_List *coll; - Eina_List *in, *l, *ll; - Eina_File *f; + Eina_List *in, *ll; + Elm_Theme_File *etf; - EINA_LIST_FOREACH(handles, l, f) + EINA_INLIST_FOREACH(handles, etf) { - coll = edje_mmap_collection_list(f); + coll = edje_mmap_collection_list(etf->handle); EINA_LIST_FOREACH(coll, ll, c) { // if base == start of collection str @@ -950,11 +967,11 @@ elm_theme_group_base_list(Elm_Theme *th, const char *base) // XXX: look results up in a hash for speed len = strlen(base); // go through all possible theme files and find collections that match - list = _elm_theme_file_group_base_list(NULL, th->overlay.handles, + list = _elm_theme_file_group_base_list(NULL, th->overlay, base, len); - list = _elm_theme_file_group_base_list(list, th->themes.handles, + list = _elm_theme_file_group_base_list(list, th->themes, base, len); - list = _elm_theme_file_group_base_list(list, th->extension.handles, + list = _elm_theme_file_group_base_list(list, th->extension, base, len); // sort the list nicely at the end --
