diff --git a/src/bin/ui/ui_cache.c b/src/bin/ui/ui_cache.c index 38210df..a8df15a 100644 --- a/src/bin/ui/ui_cache.c +++ b/src/bin/ui/ui_cache.c @@ -14,7 +14,7 @@ evisum_ui_item_cache_new(Evas_Object *parent, for (int i = 0; i < size; i++) { - Item_Cache *it = calloc(1, sizeof(Item_Cache)); + Item_Cache *it = malloc(sizeof(Item_Cache)); if (it) { it->obj = cache->item_create_cb(parent); @@ -25,6 +25,43 @@ evisum_ui_item_cache_new(Evas_Object *parent, return cache; } +void +evisum_ui_item_cache_steal(Evisum_Ui_Cache *cache, Eina_List *objs) +{ + Eina_List *l, *l_next, *l2; + Item_Cache *it; + Evas_Object *o; + + EINA_LIST_FOREACH_SAFE(cache->active, l, l_next, it) + { + int found = 0; + EINA_LIST_FOREACH(objs, l2, o) + { + if (it->obj == o) + { + found = 1; + break; + } + } + if (!found) + { + cache->active = eina_list_remove_list(cache->active, l); + evas_object_del(it->obj); + free(it); + } + } + if (eina_list_count(cache->inactive)) return; + for (int i = 0; i < cache->size; i++) + { + Item_Cache *it = malloc(sizeof(Item_Cache)); + if (it) + { + it->obj = cache->item_create_cb(cache->parent); + cache->inactive = eina_list_prepend(cache->inactive, it); + } + } +} + Item_Cache * evisum_ui_item_cache_item_get(Evisum_Ui_Cache *cache) { @@ -79,6 +116,7 @@ evisum_ui_item_cache_item_release(Evisum_Ui_Cache *cache, Evas_Object *obj) Eina_List *l, *l_next; Eina_Bool released = EINA_FALSE; + if (!cache->active) return EINA_FALSE; int n = eina_list_count(cache->inactive); EINA_LIST_FOREACH_SAFE(cache->active, l, l_next, it) diff --git a/src/bin/ui/ui_cache.h b/src/bin/ui/ui_cache.h index 461ea71..5d595c2 100644 --- a/src/bin/ui/ui_cache.h +++ b/src/bin/ui/ui_cache.h @@ -31,5 +31,8 @@ evisum_ui_item_cache_free(Evisum_Ui_Cache *cache); void evisum_ui_item_cache_reset(Evisum_Ui_Cache *cache); +void +evisum_ui_item_cache_steal(Evisum_Ui_Cache *cache, Eina_List *objs); + #endif diff --git a/src/bin/ui/ui_process_list.c b/src/bin/ui/ui_process_list.c index 8538f8a..2af3aa8 100644 --- a/src/bin/ui/ui_process_list.c +++ b/src/bin/ui/ui_process_list.c @@ -227,7 +227,10 @@ _item_unrealized_cb(void *data, Evas_Object *obj EINA_UNUSED, EINA_LIST_FREE(contents, o) { - evisum_ui_item_cache_item_release(pd->cache, o); + if (!evisum_ui_item_cache_item_release(pd->cache, o)) + { + evas_object_del(o); + } } } @@ -548,7 +551,9 @@ _genlist_ensure_n_items(Evas_Object *genlist, unsigned int items, { it = elm_genlist_last_item_get(genlist); if (it) - elm_object_item_del(it); + { + elm_object_item_del(it); + } } } @@ -775,8 +780,7 @@ _process_list_feedback_cb(void *data, Ecore_Thread *thread EINA_UNUSED, int n = eina_list_count(pd->cache->active); if (n > eina_list_count(real) * 2) { - elm_genlist_clear(pd->genlist); - evisum_ui_item_cache_reset(pd->cache); + evisum_ui_item_cache_steal(pd->cache, real); pd->skip_wait = 1; } eina_list_free(real);