netstar pushed a commit to branch master. http://git.enlightenment.org/apps/evisum.git/commit/?id=74cdce3f293420c928430ab116091f4e0614977d
commit 74cdce3f293420c928430ab116091f4e0614977d Author: Alastair Poole <nets...@gmail.com> Date: Mon Jan 4 10:26:38 2021 +0000 cache: ...? two list accounting, but something fishy... --- src/bin/ui/ui_cache.c | 78 +++++++++++++++++++++----------------------- src/bin/ui/ui_cache.h | 4 +-- src/bin/ui/ui_process_list.c | 2 ++ 3 files changed, 41 insertions(+), 43 deletions(-) diff --git a/src/bin/ui/ui_cache.c b/src/bin/ui/ui_cache.c index 2c3f596..5c3cf16 100644 --- a/src/bin/ui/ui_cache.c +++ b/src/bin/ui/ui_cache.c @@ -9,7 +9,7 @@ evisum_ui_item_cache_new(Evas_Object *parent, cache->parent = parent; cache->item_create_cb = create_cb; - cache->items = NULL; + cache->inactive = cache->active = NULL; cache->time = time(NULL); for (int i = 0; i < size; i++) @@ -18,7 +18,7 @@ evisum_ui_item_cache_new(Evas_Object *parent, if (it) { it->obj = cache->item_create_cb(parent); - cache->items = eina_list_append(cache->items, it); + cache->inactive = eina_list_append(cache->inactive, it); } } @@ -28,69 +28,65 @@ evisum_ui_item_cache_new(Evas_Object *parent, Item_Cache * evisum_ui_item_cache_item_get(Evisum_Ui_Cache *cache) { - Eina_List *l; + Eina_List *l, *l_next; Item_Cache *it; - EINA_LIST_FOREACH(cache->items, l, it) + EINA_LIST_FOREACH_SAFE(cache->inactive, l, l_next, it) { - if (it->used == 0) - { - it->used = 1; - return it; - } + cache->inactive = eina_list_remove_list(cache->inactive, l); + cache->active = eina_list_prepend(cache->active, it); + return it; } it = calloc(1, sizeof(Item_Cache)); if (it) { + for (int i = 0; i < 10; i++) + { + Item_Cache *it = calloc(1, sizeof(Item_Cache)); + if (it) + { + it->obj = cache->item_create_cb(cache->parent); + cache->inactive = eina_list_append(cache->inactive, it); + } + } + it->obj = cache->item_create_cb(cache->parent); - it->used = 1; - cache->items = eina_list_append(cache->items, it); + cache->active = eina_list_prepend(cache->active, it); } return it; } -static int -_clean_cb(const void *p1, const void *p2) -{ - Item_Cache *c1, *c2; - - c1 = (Item_Cache *) p1; - c2 = (Item_Cache *) p1; - - if (c1->used == 0 || c2->used == 0) - return -1; - - return 1; -} - Eina_Bool evisum_ui_item_cache_item_release(Evisum_Ui_Cache *cache, Evas_Object *obj) { Item_Cache *it; - Eina_List *l; + Eina_List *l, *l_next; Eina_Bool released = EINA_FALSE; - time_t now = time(NULL); - if ((now - cache->time) > 60) - { - cache->items = eina_list_sort(cache->items, - eina_list_count(cache->items), - _clean_cb); - cache->time = now; - } + int n = eina_list_count(cache->inactive); - EINA_LIST_FOREACH(cache->items, l, it) + EINA_LIST_FOREACH_SAFE(cache->active, l, l_next, it) { if (it->obj == obj) { - it->used = 0; - evas_object_hide(it->obj); + cache->active = eina_list_remove_list(cache->active, l); + if (n >= 50) + { + evas_object_del(it->obj); + free(it); + } + else + { + evas_object_hide(it->obj); + cache->inactive = eina_list_prepend(cache->inactive, it); + } released = EINA_TRUE; break; } } + return released; } @@ -101,9 +97,9 @@ evisum_ui_item_cache_free(Evisum_Ui_Cache *cache) evas_object_del(cache->parent); - EINA_LIST_FREE(cache->items, it) - { - free(it); - } + EINA_LIST_FREE(cache->active, it) + free(it); + EINA_LIST_FREE(cache->inactive, it) + free(it); free(cache); } diff --git a/src/bin/ui/ui_cache.h b/src/bin/ui/ui_cache.h index 767d4dc..6764141 100644 --- a/src/bin/ui/ui_cache.h +++ b/src/bin/ui/ui_cache.h @@ -5,7 +5,8 @@ #include <Evas.h> typedef struct _Evisum_Ui_Cache { - Eina_List *items; + Eina_List *inactive; + Eina_List *active; Evas_Object *parent; Evas_Object *(*item_create_cb)(Evas_Object *); time_t time; @@ -13,7 +14,6 @@ typedef struct _Evisum_Ui_Cache { typedef struct _Item_Cache { Evas_Object *obj; - Eina_Bool used; } Item_Cache; Evisum_Ui_Cache * diff --git a/src/bin/ui/ui_process_list.c b/src/bin/ui/ui_process_list.c index 19930d8..c5a52e2 100644 --- a/src/bin/ui/ui_process_list.c +++ b/src/bin/ui/ui_process_list.c @@ -732,6 +732,8 @@ _process_list(void *data, Ecore_Thread *thread) } delay = ui->proc.poll_delay; + printf("active %d and inactive %d\n", eina_list_count(pd->cache->active), + eina_list_count(pd->cache->inactive)); } } --