diff options
author | Marcel Hollerbach <mail@marcel-hollerbach.de> | 2019-08-18 20:24:02 +0200 |
---|---|---|
committer | Marcel Hollerbach <mail@marcel-hollerbach.de> | 2019-08-18 20:24:02 +0200 |
commit | 8d35a283b0f20fbcab42d32b565d8bb064573e22 (patch) | |
tree | db3c8e99081039fd3b7d62a99a15f651154c4e75 | |
parent | 6e58aa151d8ecb4ba7aeed3b339bf697007aa70d (diff) | |
download | efl-8d35a283b0f20fbcab42d32b565d8bb064573e22.tar.gz |
-rw-r--r-- | src/lib/elementary/efl_ui_collection.c | 94 |
1 files changed, 17 insertions, 77 deletions
diff --git a/src/lib/elementary/efl_ui_collection.c b/src/lib/elementary/efl_ui_collection.c index a7f42ef3a8..a4907a0a5a 100644 --- a/src/lib/elementary/efl_ui_collection.c +++ b/src/lib/elementary/efl_ui_collection.c @@ -21,65 +21,26 @@ typedef struct { unsigned int last_index; const Eina_List *current; Eina_List **items; + Eina_Array *cache; } Fast_Accessor; static const Eina_List* _fast_accessor_get_at(Fast_Accessor *accessor, unsigned int idx) { - const Eina_List *over; - unsigned int middle; - unsigned int i; - - if (idx >= eina_list_count(*accessor->items)) - return NULL; - - if (accessor->last_index == idx) - over = accessor->current; - else if (idx > accessor->last_index) - { - /* After current position. */ - middle = ((eina_list_count(*accessor->items) - accessor->last_index))/2; - - if (idx > middle) - /* Go backward from the end. */ - for (i = eina_list_count(*accessor->items) - 1, - over = eina_list_last(*accessor->items); - i > idx && over; - --i, over = eina_list_prev(over)) - ; - else - /* Go forward from current. */ - for (i = accessor->last_index, over = accessor->current; - i < idx && over; - ++i, over = eina_list_next(over)) - ; - } - else + if (!accessor->cache) { - /* Before current position. */ - middle = accessor->last_index/2; - - if (idx > middle) - /* Go backward from current. */ - for (i = accessor->last_index, over = accessor->current; - i > idx && over; - --i, over = eina_list_prev(over)) - ; - else - /* Go forward from start. */ - for (i = 0, over = *accessor->items; - i < idx && over; - ++i, over = eina_list_next(over)) - ; - } - - if (!over) - return NULL; + Eina_List *n; + Eo *o; - accessor->last_index = idx; - accessor->current = over; + accessor->cache = eina_array_new(100); - return over; + EINA_LIST_FOREACH(*accessor->items, n, o) + { + eina_array_push(accessor->cache, n); + printf("%p\n", o); + } + } + return eina_array_data_get(accessor->cache, idx); } static void @@ -94,32 +55,9 @@ _fast_accessor_init(Fast_Accessor *accessor, Eina_List **items) static void _fast_accessor_remove(Fast_Accessor *accessor, const Eina_List *removed_elem) { - if (accessor->current == removed_elem) - { - Eina_List *next; - Eina_List *prev; - - next = eina_list_next(removed_elem); - prev = eina_list_prev(removed_elem); - if (next) - { - accessor->current = next; - accessor->last_index ++; - } - else if (prev) - { - accessor->current = prev; - accessor->last_index --; - } - else - { - //everything >= length is invalid, and we need that. - accessor->last_index = eina_list_count(*accessor->items); - accessor->current = NULL; - } - - } - + if (accessor->cache) + eina_array_free(accessor->cache); + accessor->cache = NULL; } #define MY_CLASS EFL_UI_COLLECTION_CLASS @@ -587,6 +525,8 @@ register_item(Eo *obj, Efl_Ui_Collection_Data *pd, Efl_Ui_Item *item) efl_canvas_group_member_add(pd->pan, item); efl_event_callback_array_add(item, active_item(), obj); efl_ui_mirrored_set(item, efl_ui_mirrored_get(obj)); + _fast_accessor_remove(&pd->obj_accessor, NULL); + _fast_accessor_remove(&pd->size_accessor, NULL); return EINA_TRUE; } |