This is an automated email from the git hooks/post-receive script.

git pushed a commit to branch master
in repository efl.

View the commit online.

commit 586974dcac5c693be9891d543f870e133dbd9e20
Author: Cedric BAIL <[email protected]>
AuthorDate: Sun Nov 15 20:23:34 2026 -0600

    elementary: position_manager_list: the size cache follows item changes
    
    Every addition, removal or size change threw the sum cache away, and the
    next use asked the size of every item again: a list that grows one item
    at a time, with the loop idling in between, asked about two million
    items for 2000 of them. Most of the cache is not wrong after a change,
    only shifted.
    
    Keep the sums when an item comes or goes (the entries after are moved by
    its size) and when a range is reported measured again (the range is
    asked again and the entries after it move by what it gained). What
    changed is asked for when the cache is next needed, the items that came
    in the meantime together: asking a provider about an item it has not got
    can be a request for it, an eager question for each item of a thousand
    added in a row was ten times slower than not asking, and a provider does
    not always answer in the middle of a change what it does when it is
    done. The last item the cache had is asked again each time, and a size
    that is not the one in the cache gives the incremental update up for the
    full one, which is kept for a model swap and for a cache that was not
    built.
    
    The maximum of the minimum sizes is only raised until the next full
    build.
    
    The test counts the rows the view is asked the size of through a
    position manager that wraps the callback (2113055 for 2000 added with
    the loop idling before, 16006 now), and a second one moves rows about in
    a manager of its own and checks every place against the sizes.
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
 src/lib/elementary/efl_ui_position_manager_list.c  | 332 ++++++++++++++++++++-
 src/tests/elementary/efl_ui_test_collection_view.c | 281 +++++++++++++++--
 2 files changed, 589 insertions(+), 24 deletions(-)

diff --git a/src/lib/elementary/efl_ui_position_manager_list.c b/src/lib/elementary/efl_ui_position_manager_list.c
index 4fc7d074f5..76b7daac34 100644
--- a/src/lib/elementary/efl_ui_position_manager_list.c
+++ b/src/lib/elementary/efl_ui_position_manager_list.c
@@ -3,6 +3,7 @@
 #endif
 
 
+#include <limits.h>
 #include <Efl_Ui.h>
 #include <Elementary.h>
 #include "elm_widget.h"
@@ -31,8 +32,13 @@ typedef struct {
    Efl_Ui_Layout_Orientation dir;
 
    unsigned int size;
+   unsigned int cache_size;
+   // Items of the cache that are to be asked for again (dirty_lo <= dirty_hi), once it is needed
+   unsigned int dirty_lo;
+   unsigned int dirty_hi;
    int average_item_size;
    int maximum_min_size;
+   Eina_Bool dirty : 1;
 } Efl_Ui_Position_Manager_List_Data;
 
 /*
@@ -49,8 +55,12 @@ cache_invalidate(Eo *obj EINA_UNUSED, Efl_Ui_Position_Manager_List_Data *pd)
    if (pd->size_cache)
      free(pd->size_cache);
    pd->size_cache = NULL;
+   pd->cache_size = 0;
+   pd->dirty = EINA_FALSE;
 }
 
+static void _cache_changes_apply(Eo *obj, Efl_Ui_Position_Manager_List_Data *pd);
+
 static void
 cache_require(Eo *obj EINA_UNUSED, Efl_Ui_Position_Manager_List_Data *pd)
 {
@@ -59,7 +69,15 @@ cache_require(Eo *obj EINA_UNUSED, Efl_Ui_Position_Manager_List_Data *pd)
    Efl_Ui_Position_Manager_Size_Batch_Entity size_buffer[len];
    Efl_Ui_Position_Manager_Size_Batch_Result size_result;
 
-   if (pd->size_cache) return;
+   if (pd->size_cache)
+     {
+        // What changed since is asked for now, all at once
+        if ((pd->dirty) || (pd->size != pd->cache_size))
+          {
+             _cache_changes_apply(obj, pd);
+          }
+        if (pd->size_cache) return;
+     }
 
    if (pd->size == 0)
      {
@@ -101,11 +119,311 @@ cache_require(Eo *obj EINA_UNUSED, Efl_Ui_Position_Manager_List_Data *pd)
         /* no point iterating further if size calc can't be done yet */
         //if ((!i) && (!pd->maximum_min_size)) break;
      }
+   pd->cache_size = pd->size;
    pd->average_item_size = pd->size_cache[pd->size]/pd->size;
    if ((!pd->average_item_size) && (!pd->maximum_min_size))
      cache_invalidate(obj, pd);
 }
 
+/*
+ * A change to a few items does not make the rest of the cache wrong, only
+ * shifted: the sum of every item after the change moves by what the change
+ * added. Asking again for all of the items to learn that is what made a list
+ * that grows by one item at a time ask for every item it had at each addition.
+ *
+ * What changed is not asked for at once but when the cache is next needed (the
+ * job that follows a change), everything that came in the meantime together:
+ * asking a provider about an item it has not got yet can be a request for that
+ * item, and a request for each of a thousand items added in a row is not the
+ * same as a request for a thousand items, and what a provider says in the
+ * middle of a change is not what it says once the change is done.
+ *
+ * What is not known about the other items is whether they are the same, if
+ * the answer of the provider is something that changes under them (the average
+ * of what was measured, the size of the view before anything was: measuring
+ * the last of three items makes the other two the size it has). So the first
+ * and the last item the cache had, which are asked again if they were not
+ * among those just asked, must be the size the cache has, or the incremental
+ * update is given up for a full one.
+ *
+ * The maximum of the minimum size is only ever raised by these updates: an
+ * item that leaves does not tell its own, and it is a bound that stays
+ * until the next full build.
+ */
+static Eina_Bool
+_cache_range_ask(Efl_Ui_Position_Manager_List_Data *pd, unsigned int start, unsigned int end,
+                 int *steps, int *max_min)
+{
+   Efl_Ui_Position_Manager_Size_Batch_Entity size_buffer[100];
+   Efl_Ui_Position_Manager_Size_Batch_Result size_result;
+   unsigned int i;
+
+   for (i = start; i < end; i++)
+     {
+        unsigned int buffer_id = (i - start) % 100;
+        Eina_Size2D size;
+        int min, step;
+
+        if (buffer_id == 0)
+          {
+             size_result = _batch_request_size(pd->callbacks, i, end, MIN(100, end - i),
+                                               EINA_TRUE, size_buffer);
+             if (size_result.filled_items == 0) return EINA_FALSE;
+          }
+        size = size_buffer[buffer_id].size;
+        if (pd->dir == EFL_UI_LAYOUT_ORIENTATION_VERTICAL)
+          {
+             step = size.h;
+             min = size.w;
+          }
+        else
+          {
+             step = size.w;
+             min = size.h;
+          }
+        steps[i - start] = step;
+        *max_min = MAX(*max_min, min);
+     }
+   return EINA_TRUE;
+}
+
+// The item of the cache is of the size the cache has for it.
+static Eina_Bool
+_cache_probe(Efl_Ui_Position_Manager_List_Data *pd, unsigned int item)
+{
+   int step = 0, max_min = 0;
+
+   if (item >= pd->cache_size) return EINA_TRUE;
+   if (!_cache_range_ask(pd, item, item + 1, &step, &max_min)) return EINA_FALSE;
+   return (pd->size_cache[item + 1] - pd->size_cache[item]) == step;
+}
+
+// What the cache holds is checked after it was changed, on the first and the
+// last of its items, if they are not among those that were just asked.
+static void
+_cache_checked(Eo *obj, Efl_Ui_Position_Manager_List_Data *pd,
+               unsigned int lo1, unsigned int hi1, unsigned int lo2, unsigned int hi2)
+{
+   unsigned int probes[2];
+   unsigned int i;
+
+   if (!pd->cache_size) goto full;
+   pd->average_item_size = pd->size_cache[pd->cache_size] / pd->cache_size;
+   if (!pd->average_item_size && !pd->maximum_min_size) goto full;
+
+   probes[0] = 0;
+   probes[1] = pd->cache_size - 1;
+   for (i = 0; i < 2; i++)
+     {
+        if (((probes[i] >= lo1) && (probes[i] <= hi1)) ||
+            ((probes[i] >= lo2) && (probes[i] <= hi2)) ||
+            (i && (probes[0] == probes[1])))
+          continue;
+        if (!_cache_probe(pd, probes[i])) goto full;
+     }
+   return;
+
+ full:
+   cache_invalidate(obj, pd);
+}
+
+static void
+_cache_dirty(Efl_Ui_Position_Manager_List_Data *pd, unsigned int start, unsigned int end)
+{
+   if (!pd->dirty)
+     {
+        pd->dirty_lo = start;
+        pd->dirty_hi = end;
+        pd->dirty = EINA_TRUE;
+        return;
+     }
+   pd->dirty_lo = MIN(pd->dirty_lo, start);
+   pd->dirty_hi = MAX(pd->dirty_hi, end);
+}
+
+// The items that changed are asked for, then those appended
+static void
+_cache_changes_apply(Eo *obj, Efl_Ui_Position_Manager_List_Data *pd)
+{
+   unsigned int from, to, i;
+   // What is asked here (nothing, when the low one is above the high one)
+   unsigned int dirty_lo = 1, dirty_hi = 0, new_lo = 1, new_hi = 0;
+   int *cache, *steps;
+   int max_min = pd->maximum_min_size;
+   int old_end, delta;
+
+   if (pd->size < pd->cache_size) goto full;
+
+   if (pd->dirty)
+     {
+        from = pd->dirty_lo;
+        to = MIN(pd->dirty_hi + 1, pd->cache_size);
+        pd->dirty = EINA_FALSE;
+        if (from < to)
+          {
+             steps = malloc((to - from) * sizeof (int));
+             if (!steps) goto full;
+             if (!_cache_range_ask(pd, from, to, steps, &max_min))
+               {
+                  free(steps);
+                  goto full;
+               }
+             dirty_lo = from;
+             dirty_hi = to - 1;
+             old_end = pd->size_cache[to];
+             for (i = from; i < to; i++)
+               {
+                  pd->size_cache[i + 1] = pd->size_cache[i] + steps[i - from];
+               }
+             free(steps);
+             // What is after the range moves by what the range gained
+             delta = pd->size_cache[to] - old_end;
+             if (delta)
+               {
+                  for (i = to + 1; i <= pd->cache_size; i++)
+                    {
+                       pd->size_cache[i] += delta;
+                    }
+               }
+          }
+     }
+
+   from = pd->cache_size;
+   to = pd->size;
+   if (to > from)
+     {
+        steps = malloc((to - from) * sizeof (int));
+        if (!steps) goto full;
+        if (!_cache_range_ask(pd, from, to, steps, &max_min))
+          {
+             free(steps);
+             goto full;
+          }
+        cache = realloc(pd->size_cache, (to + 1) * sizeof (int));
+        if (!cache)
+          {
+             free(steps);
+             goto full;
+          }
+        pd->size_cache = cache;
+        for (i = from; i < to; i++)
+          {
+             cache[i + 1] = cache[i] + steps[i - from];
+          }
+        free(steps);
+        pd->cache_size = to;
+        new_lo = from;
+        new_hi = to - 1;
+     }
+
+   pd->maximum_min_size = max_min;
+   _cache_checked(obj, pd, dirty_lo, dirty_hi, new_lo, new_hi);
+   return;
+
+ full:
+   cache_invalidate(obj, pd);
+}
+
+// What is after the items that were asked for moves with them
+static void
+_cache_item_added(Eo *obj, Efl_Ui_Position_Manager_List_Data *pd, unsigned int idx)
+{
+   int *cache;
+
+   // Not built: the first build will have the item
+   if (!pd->size_cache) return;
+   // Past what the cache has: asked for with the others that came, when it is needed
+   if (idx >= pd->cache_size) return;
+
+   cache = realloc(pd->size_cache, (pd->cache_size + 2) * sizeof (int));
+   if (!cache)
+     {
+        cache_invalidate(obj, pd);
+        return;
+     }
+   pd->size_cache = cache;
+
+   // The entries up to idx are where they were, those after are one further.
+   // The item is of no size until it is asked for.
+   memmove(cache + idx + 2, cache + idx + 1, (pd->cache_size - idx) * sizeof (int));
+   cache[idx + 1] = cache[idx];
+   pd->cache_size++;
+   if (pd->dirty)
+     {
+        if (idx <= pd->dirty_lo)
+          {
+             pd->dirty_lo++;
+             pd->dirty_hi++;
+          }
+        else if (idx <= pd->dirty_hi)
+          {
+             pd->dirty_hi++;
+          }
+     }
+   _cache_dirty(pd, idx, idx);
+}
+
+// (pd->size is what is left)
+static void
+_cache_item_removed(Eo *obj, Efl_Ui_Position_Manager_List_Data *pd, unsigned int idx)
+{
+   int *cache = pd->size_cache;
+   int step;
+   unsigned int i;
+
+   if (!cache) return;
+   // One of those not asked for yet
+   if (idx >= pd->cache_size)
+     {
+        if (pd->size < pd->cache_size) cache_invalidate(obj, pd);
+        return;
+     }
+
+   step = cache[idx + 1] - cache[idx];
+   memmove(cache + idx + 1, cache + idx + 2, (pd->cache_size - 1 - idx) * sizeof (int));
+   pd->cache_size--;
+   for (i = idx + 1; i <= pd->cache_size; i++)
+     {
+        cache[i] -= step;
+     }
+   if (pd->dirty)
+     {
+        if (idx < pd->dirty_lo)
+          {
+             pd->dirty_lo--;
+             pd->dirty_hi--;
+          }
+        else if (idx <= pd->dirty_hi)
+          {
+             if (pd->dirty_lo == pd->dirty_hi)
+               {
+                  pd->dirty = EINA_FALSE;
+               }
+             else
+               {
+                  pd->dirty_hi--;
+               }
+          }
+     }
+   if (!pd->cache_size) cache_invalidate(obj, pd);
+}
+
+// The items from start to end (included) have another size now.
+static void
+_cache_item_size_changed(Eo *obj, Efl_Ui_Position_Manager_List_Data *pd,
+                         unsigned int start, unsigned int end)
+{
+   if (!pd->size_cache) return;
+   if (start > end)
+     {
+        cache_invalidate(obj, pd);
+        return;
+     }
+   // The items not asked for yet will be, as they are then
+   if (start >= pd->cache_size) return;
+   _cache_dirty(pd, start, MIN(end, pd->cache_size - 1));
+}
+
 static int
 cache_access(Eo *obj EINA_UNUSED, Efl_Ui_Position_Manager_List_Data *pd, unsigned int idx)
 {
@@ -408,7 +726,7 @@ _efl_ui_position_manager_list_efl_ui_position_manager_entity_scroll_position_set
 }
 
 EOLIAN static void
-_efl_ui_position_manager_list_efl_ui_position_manager_entity_item_added(Eo *obj, Efl_Ui_Position_Manager_List_Data *pd, int added_index EINA_UNUSED, Efl_Gfx_Entity *subobj)
+_efl_ui_position_manager_list_efl_ui_position_manager_entity_item_added(Eo *obj, Efl_Ui_Position_Manager_List_Data *pd, int added_index, Efl_Gfx_Entity *subobj)
 {
    if (pd->size == 0)
      {
@@ -420,19 +738,19 @@ _efl_ui_position_manager_list_efl_ui_position_manager_entity_item_added(Eo *obj,
      {
         efl_gfx_entity_visible_set(subobj, EINA_FALSE);
      }
-   cache_invalidate(obj, pd);
+   _cache_item_added(obj, pd, added_index);
    schedule_recalc_absolut_size(obj, pd);
 }
 
 EOLIAN static void
-_efl_ui_position_manager_list_efl_ui_position_manager_entity_item_removed(Eo *obj, Efl_Ui_Position_Manager_List_Data *pd, int removed_index EINA_UNUSED, Efl_Gfx_Entity *subobj)
+_efl_ui_position_manager_list_efl_ui_position_manager_entity_item_removed(Eo *obj, Efl_Ui_Position_Manager_List_Data *pd, int removed_index, Efl_Gfx_Entity *subobj)
 {
    pd->size --;
    if (subobj)
      {
         efl_gfx_entity_visible_set(subobj, EINA_TRUE);
      }
-   cache_invalidate(obj, pd);
+   _cache_item_removed(obj, pd, removed_index);
    schedule_recalc_absolut_size(obj, pd);
 }
 
@@ -486,9 +804,9 @@ _efl_ui_position_manager_list_efl_ui_position_manager_entity_position_single_ite
 }
 
 EOLIAN static void
-_efl_ui_position_manager_list_efl_ui_position_manager_entity_item_size_changed(Eo *obj, Efl_Ui_Position_Manager_List_Data *pd, int start_id EINA_UNUSED, int end_id EINA_UNUSED)
+_efl_ui_position_manager_list_efl_ui_position_manager_entity_item_size_changed(Eo *obj, Efl_Ui_Position_Manager_List_Data *pd, int start_id, int end_id)
 {
-   cache_invalidate(obj, pd);
+   _cache_item_size_changed(obj, pd, start_id, end_id);
    schedule_recalc_absolut_size(obj, pd);
 }
 
diff --git a/src/tests/elementary/efl_ui_test_collection_view.c b/src/tests/elementary/efl_ui_test_collection_view.c
index ec2d03ff46..ced64a6051 100644
--- a/src/tests/elementary/efl_ui_test_collection_view.c
+++ b/src/tests/elementary/efl_ui_test_collection_view.c
@@ -8,6 +8,7 @@
 #include "efl_ui_exact_model.eo.h"
 
 #define NUM_ITEMS 50
+#define SINGLE_ADDS 2000
 
 static Efl_Model*
 _make_model(Efl_Ui_Win *win)
@@ -1038,42 +1039,286 @@ EFL_START_TEST(test_efl_ui_collection_view_exact_model_jump)
 }
 EFL_END_TEST
 
-/* Rows are added one at a time to a view that is showing the model, as a
-   listing arriving does, and the loop is let to idle in between. */
-static void
-_single_adds(Efl_Model *model, int rows)
-{
-   int i;
+/* The cache of the list position manager follows rows that are added,
+   removed or measured again without being built again: each time it is
+   needed, the place of every row must be where the sizes of the rows before
+   say it is, whatever happened in between. */
+#define CACHE_MAX_ROWS 400
+static int _cache_sizes[CACHE_MAX_ROWS];
+static unsigned int _cache_count = 0;
 
-   for (i = 0; i < rows; i++)
+static Efl_Ui_Position_Manager_Size_Batch_Result
+_cache_size_cb(void *data EINA_UNUSED, Efl_Ui_Position_Manager_Size_Call_Config conf,
+               Eina_Rw_Slice memory)
+{
+   Efl_Ui_Position_Manager_Size_Batch_Entity *sizes = memory.mem;
+   Efl_Ui_Position_Manager_Size_Batch_Result result = { 0 };
+   unsigned int i, limit = conf.range.end_id - conf.range.start_id;
+
+   for (i = 0; (i < limit) && conf.range.start_id + i < _cache_count; i++)
      {
-        efl_model_child_add(model);
-        wait_timer(0.0);
+        sizes[i].size = EINA_SIZE2D(20, _cache_sizes[conf.range.start_id + i]);
+        sizes[i].element_depth = 0;
+        sizes[i].depth_leader = EINA_FALSE;
      }
+   result.filled_items = i;
+   return result;
 }
 
-/* A view over an Exact_Model is asked the size of every row each time one
-   comes in. How long 2000 of them take depends on the machine, and is not
-   asserted. */
-EFL_START_TEST(test_efl_ui_collection_view_many_single_adds)
+static Efl_Ui_Position_Manager_Object_Batch_Result
+_cache_object_cb(void *data EINA_UNUSED, Efl_Ui_Position_Manager_Request_Range range EINA_UNUSED,
+                 Eina_Rw_Slice memory EINA_UNUSED)
+{
+   Efl_Ui_Position_Manager_Object_Batch_Result result = { 0 };
+
+   return result;
+}
+
+static int _cache_content_h = -1;
+
+static void
+_cache_content_size(void *data EINA_UNUSED, const Efl_Event *ev)
+{
+   Eina_Size2D *size = ev->info;
+
+   _cache_content_h = size->h;
+}
+
+static void
+_cache_places_check(Efl_Ui_Position_Manager_Entity *manager)
+{
+   unsigned int i;
+   int y = 0;
+
+   // The job that follows the changes gives the size of the content
+   ecore_main_loop_iterate();
+
+   for (i = 0; i < _cache_count; i++)
+     {
+        Eina_Rect g = efl_ui_position_manager_entity_position_single_item(manager, i);
+
+        ck_assert_int_eq(g.y, y);
+        ck_assert_int_eq(g.h, _cache_sizes[i]);
+        y += _cache_sizes[i];
+     }
+   ck_assert_int_eq(_cache_content_h, y);
+}
+
+EFL_START_TEST(test_efl_ui_position_manager_list_cache_follows)
+{
+   Efl_Ui_Win *win;
+   Efl_Ui_Position_Manager_Entity *manager;
+   unsigned int seed = 7, i, step;
+
+   win = win_add(NULL, "win", EFL_UI_WIN_TYPE_BASIC);
+   manager = efl_add(EFL_UI_POSITION_MANAGER_LIST_CLASS, win,
+                     efl_ui_layout_orientation_set(efl_added, EFL_UI_LAYOUT_ORIENTATION_VERTICAL));
+   efl_event_callback_add(manager, EFL_UI_POSITION_MANAGER_ENTITY_EVENT_CONTENT_SIZE_CHANGED,
+                          _cache_content_size, NULL);
+   _cache_content_h = -1;
+   for (i = 0; i < 6; i++)
+     {
+        _cache_sizes[i] = 10 * (i + 1);
+     }
+   _cache_count = 6;
+   efl_ui_position_manager_data_access_v1_data_access_set(manager, win, NULL, _cache_object_cb, NULL,
+                                                          NULL, _cache_size_cb, NULL, _cache_count);
+   efl_ui_position_manager_entity_viewport_set(manager, EINA_RECT(0, 0, 100, 1));
+   _cache_places_check(manager);
+
+   for (step = 0; step < 600; step++)
+     {
+        unsigned int idx;
+
+        seed = seed * 1103515245 + 12345;
+        idx = (seed >> 8) % 8;
+        seed = seed * 1103515245 + 12345;
+        switch ((seed >> 8) % 6)
+          {
+           case 0: /* added in front */
+           case 1: /* added somewhere */
+           case 2: /* appended */
+             {
+                unsigned int at;
+
+                if (_cache_count >= CACHE_MAX_ROWS - 1) break;
+                at = ((seed >> 8) % 6 == 0) ? 0 :
+                  (((seed >> 8) % 6 == 2) ? _cache_count : (idx % (_cache_count + 1)));
+                memmove(_cache_sizes + at + 1, _cache_sizes + at,
+                        (_cache_count - at) * sizeof (int));
+                _cache_sizes[at] = 5 + (seed >> 16) % 60;
+                _cache_count++;
+                efl_ui_position_manager_entity_item_added(manager, at, NULL);
+                break;
+             }
+           case 3: /* removed */
+             {
+                unsigned int at;
+
+                if (_cache_count < 2) break;
+                at = idx % _cache_count;
+                memmove(_cache_sizes + at, _cache_sizes + at + 1,
+                        (_cache_count - at - 1) * sizeof (int));
+                _cache_count--;
+                efl_ui_position_manager_entity_item_removed(manager, at, NULL);
+                break;
+             }
+           default: /* measured again */
+             {
+                unsigned int start = idx % _cache_count;
+                unsigned int end = MIN(start + (seed >> 12) % 3, _cache_count - 1);
+                unsigned int j;
+
+                for (j = start; j <= end; j++)
+                  {
+                     _cache_sizes[j] = 5 + (seed >> (4 + j % 8)) % 60;
+                  }
+                efl_ui_position_manager_entity_item_size_changed(manager, start, end);
+                break;
+             }
+          }
+        // Not after every change: some are to pile up
+        if (!((seed >> 20) % 3)) _cache_places_check(manager);
+     }
+   _cache_places_check(manager);
+   efl_del(manager);
+}
+EFL_END_TEST
+
+/* A position manager that counts the rows the view is asked the size of on
+   its behalf: the size callback the view gave it is wrapped by one that counts
+   what goes through. */
+static Efl_Ui_Position_Manager_Size_Batch_Callback _counted_size_access = NULL;
+static unsigned int _counted_calls = 0;
+static unsigned int _counted_rows = 0;
+
+static Efl_Ui_Position_Manager_Size_Batch_Result
+_counting_size_cb(void *data, Efl_Ui_Position_Manager_Size_Call_Config conf, Eina_Rw_Slice memory)
+{
+   _counted_calls++;
+   _counted_rows += conf.range.end_id - conf.range.start_id;
+   return _counted_size_access(data, conf, memory);
+}
+
+static void
+_counting_data_access_set(Eo *obj, void *pd EINA_UNUSED, Efl_Ui_Win *canvas,
+                          void *obj_access_data,
+                          Efl_Ui_Position_Manager_Object_Batch_Callback obj_access,
+                          Eina_Free_Cb obj_access_free_cb,
+                          void *size_access_data,
+                          Efl_Ui_Position_Manager_Size_Batch_Callback size_access,
+                          Eina_Free_Cb size_access_free_cb, int size)
+{
+   _counted_size_access = size_access;
+   efl_ui_position_manager_data_access_v1_data_access_set(efl_super(obj, efl_class_get(obj)),
+                                                          canvas, obj_access_data, obj_access,
+                                                          obj_access_free_cb, size_access_data,
+                                                          size_access ? _counting_size_cb : NULL,
+                                                          size_access_free_cb, size);
+}
+
+static Eina_Bool
+_counting_manager_initializer(Efl_Class *klass)
+{
+   EFL_OPS_DEFINE(ops,
+                  EFL_OBJECT_OP_FUNC(efl_ui_position_manager_data_access_v1_data_access_set,
+                                     _counting_data_access_set));
+
+   return efl_class_functions_set(klass, &ops, NULL);
+}
+
+static const Efl_Class *
+_counting_manager_class_get(void)
+{
+   static const Efl_Class_Description desc = {
+      EO_VERSION,
+      "Test_Counting_Position_Manager",
+      EFL_CLASS_TYPE_REGULAR,
+      0,
+      _counting_manager_initializer,
+      NULL,
+      NULL
+   };
+   static const Efl_Class *klass = NULL;
+
+   if (!klass)
+     klass = efl_class_new(&desc, EFL_UI_POSITION_MANAGER_LIST_CLASS, NULL);
+   return klass;
+}
+
+/* Rows are added one at a time to a view that is showing an Exact_Model, as a
+   listing arriving does, with the loop let to idle in between or not. The
+   rows the view is asked the size of while that goes on are counted. */
+static unsigned int
+_single_adds_rows(int rows, Eina_Bool idle)
 {
    Efl_Ui_Win *win;
    Efl_Model *model, *sizes;
+   Efl_Ui_Factory *fl;
    Efl_Ui_List_View *lv;
+   Efl_Ui_Position_Manager_Entity *manager;
    int i;
-   const int rows = 2000;
 
    win = win_add(NULL, "win", EFL_UI_WIN_TYPE_BASIC);
    efl_gfx_entity_size_set(win, EINA_SIZE2D(200, 300));
-   lv = _exact_list(win, &sizes);
-   model = efl_ui_view_model_get(sizes);
+
+   model = _make_model(win);
+   sizes = efl_add(EFL_UI_EXACT_MODEL_CLASS, win, efl_ui_view_model_set(efl_added, model));
+   manager = efl_new(_counting_manager_class_get());
+   fl = efl_add(EFL_UI_WIDGET_FACTORY_CLASS, win,
+                efl_ui_widget_factory_item_class_set(efl_added, EFL_UI_LIST_PLACEHOLDER_ITEM_CLASS),
+                efl_event_callback_add(efl_added, EFL_UI_FACTORY_EVENT_ITEM_BUILDING,
+                                       _row_height_on_build, NULL));
+   lv = efl_add(EFL_UI_LIST_VIEW_CLASS, win,
+                efl_ui_collection_view_position_manager_set(efl_added, manager),
+                efl_ui_collection_view_factory_set(efl_added, fl),
+                efl_ui_view_model_set(efl_added, sizes));
+   efl_content_set(win, lv);
    get_me_to_those_events(lv);
    for (i = 0; i < 50; i++)
      {
         ecore_main_loop_iterate();
      }
-   _single_adds(model, rows);
+
+   _counted_calls = 0;
+   _counted_rows = 0;
+   for (i = 0; i < rows; i++)
+     {
+        efl_model_child_add(model);
+        if (idle) wait_timer(0.0);
+     }
+   for (i = 0; i < 50; i++)
+     {
+        ecore_main_loop_iterate();
+     }
    ck_assert_int_eq(efl_model_children_count_get(model), NUM_ITEMS + rows);
+   return _counted_rows;
+}
+
+/* Each addition must not cost the work of all the rows already there: the
+   number of rows the view is asked the size of grows with the rows added, and
+   not with the rows added times the rows there are (2000 added one by one
+   used to make it two million). A few rows are asked about for each, to
+   be sure what is not asked again is the same. */
+EFL_START_TEST(test_efl_ui_collection_view_many_single_adds)
+{
+   const int rows = SINGLE_ADDS;
+   unsigned int counted;
+
+   counted = _single_adds_rows(rows, EINA_FALSE);
+   ck_assert_uint_lt(counted, rows * 20);
+}
+EFL_END_TEST
+
+// The same with the loop let to idle after each row, as a listing that
+// arrives slowly does.
+EFL_START_TEST(test_efl_ui_collection_view_many_single_adds_idle)
+{
+   const int rows = SINGLE_ADDS;
+   unsigned int counted;
+
+   counted = _single_adds_rows(rows, EINA_TRUE);
+   ck_assert_uint_lt(counted, rows * 20);
 }
 EFL_END_TEST
 
@@ -1171,6 +1416,8 @@ void efl_ui_test_collection_view(TCase *tc)
    tcase_add_test(tc, test_efl_ui_collection_view_sizes_agree);
    tcase_add_test(tc, test_efl_ui_collection_view_remove_last_row);
    tcase_add_test(tc, test_efl_ui_collection_view_exact_model_jump);
+   tcase_add_test(tc, test_efl_ui_position_manager_list_cache_follows);
    tcase_add_test(tc, test_efl_ui_collection_view_many_single_adds);
+   tcase_add_test(tc, test_efl_ui_collection_view_many_single_adds_idle);
    tcase_add_test(tc, test_efl_ui_collection_view_exact_model_renumbered);
 }

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.

Reply via email to