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 a361bb77ec3a7f23ea12ad4444525dc1b6da8ff9
Author: Cedric BAIL <[email protected]>
AuthorDate: Sun Nov 15 20:36:35 2026 -0600

    elementary: position_manager_list: rebuild when the provider estimates
    
    Only the first and the last item were asked again to find out whether
    the sizes of the items that were not told of had changed. With a
    provider that gives the rows nobody measured the average of those that
    were, measuring a row in the middle changes the size of every one of
    them while the two probes still match, and the cache kept the stale
    average.
    
    The size callback's result (a @beta struct, which grows a field) now
    says when some of the sizes are an estimate
    (Size_Batch_Result.estimated). A cache that holds one drops itself at
    any change, and is built again from what the provider says then. The
    probes stay for the providers that do not say. A differential test over
    a provider whose answers change (and one whose do not), with changes
    anywhere in the list, the list emptied, changes past its end and rows
    filled a few at a time, compares the manager with one given the final
    rows.
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
 .../efl_ui_position_manager_data_access_v1.eo      |   7 +
 src/lib/elementary/efl_ui_position_manager_list.c  |  56 +++++--
 src/tests/elementary/efl_ui_test_collection_view.c | 177 +++++++++++++++++++++
 3 files changed, 229 insertions(+), 11 deletions(-)

diff --git a/src/lib/elementary/efl_ui_position_manager_data_access_v1.eo b/src/lib/elementary/efl_ui_position_manager_data_access_v1.eo
index d7d42c4ad0..ff4e8ec737 100644
--- a/src/lib/elementary/efl_ui_position_manager_data_access_v1.eo
+++ b/src/lib/elementary/efl_ui_position_manager_data_access_v1.eo
@@ -32,6 +32,13 @@ struct @beta Efl.Ui.Position_Manager.Size_Batch_Result {
    parent_size : Eina.Size2D; [[The group size of the group where the first item is part of.]]
    parent_depth : ubyte; [[The depth of the parent]]
    filled_items : uint; [[The number of items that are filled into the slice.]]
+   estimated : bool; [[$true if some of the sizes given are an estimate, one that is
+                       made of what is known of the other items (the average of those
+                       measured, say) and changes when another item is measured.
+
+                       A position manager that was given such a size cannot know of
+                       the items it was not told about when it is told that some
+                       others changed, and asks for all of them again.]]
 }
 
 struct @beta Efl.Ui.Position_Manager.Size_Call_Config {
diff --git a/src/lib/elementary/efl_ui_position_manager_list.c b/src/lib/elementary/efl_ui_position_manager_list.c
index 9d97636a53..2023b4d79a 100644
--- a/src/lib/elementary/efl_ui_position_manager_list.c
+++ b/src/lib/elementary/efl_ui_position_manager_list.c
@@ -39,6 +39,9 @@ typedef struct {
    int average_item_size;
    int maximum_min_size;
    Eina_Bool dirty : 1;
+   // Some of what the cache holds is an estimate of the provider: no change is
+   // known to leave the rest of it as it is
+   Eina_Bool estimated : 1;
 } Efl_Ui_Position_Manager_List_Data;
 
 /*
@@ -57,6 +60,7 @@ cache_invalidate(Eo *obj EINA_UNUSED, Efl_Ui_Position_Manager_List_Data *pd)
    pd->size_cache = NULL;
    pd->cache_size = 0;
    pd->dirty = EINA_FALSE;
+   pd->estimated = EINA_FALSE;
 }
 
 static void _cache_changes_apply(Eo *obj, Efl_Ui_Position_Manager_List_Data *pd);
@@ -91,6 +95,7 @@ cache_require(Eo *obj EINA_UNUSED, Efl_Ui_Position_Manager_List_Data *pd)
    if (!pd->size_cache) return;
    pd->size_cache[0] = 0;
    pd->maximum_min_size = 0;
+   pd->estimated = EINA_FALSE;
 
    for (i = 0; i < pd->size; ++i)
      {
@@ -105,6 +110,7 @@ cache_require(Eo *obj EINA_UNUSED, Efl_Ui_Position_Manager_List_Data *pd)
                                                EINA_TRUE, size_buffer);
              filled = MIN(size_result.filled_items, len);
              batch_start = i;
+             if (size_result.estimated) pd->estimated = EINA_TRUE;
              if (!filled)
                {
                   // Not a cache of what is not known
@@ -149,12 +155,18 @@ cache_require(Eo *obj EINA_UNUSED, Efl_Ui_Position_Manager_List_Data *pd)
  * 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 answer of the provider is something that changes under them. A provider
+ * that gives an estimate (the average of what was measured, say) says so with
+ * the result of the size callback, and nothing is then assumed of the items
+ * that were not told of: any change drops the cache for a full build.
+ *
+ * For one that does not say so but whose answer changes still (the size of the
+ * view before anything was measured, which a shared size replaces when the
+ * first item is: measuring the last of three items makes the other two the
+ * size it has), 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. That catches the
+ * providers that change all of their answers, not those that change some.
  *
  * 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
@@ -162,7 +174,7 @@ cache_require(Eo *obj EINA_UNUSED, Efl_Ui_Position_Manager_List_Data *pd)
  */
 static Eina_Bool
 _cache_range_ask(Efl_Ui_Position_Manager_List_Data *pd, unsigned int start, unsigned int end,
-                 int *steps, int *max_min)
+                 int *steps, int *max_min, Eina_Bool *estimated)
 {
    Efl_Ui_Position_Manager_Size_Batch_Entity size_buffer[100];
    Efl_Ui_Position_Manager_Size_Batch_Result size_result;
@@ -180,6 +192,7 @@ _cache_range_ask(Efl_Ui_Position_Manager_List_Data *pd, unsigned int start, unsi
                                                EINA_TRUE, size_buffer);
              filled = MIN(size_result.filled_items, 100);
              batch_start = i;
+             if (size_result.estimated) *estimated = EINA_TRUE;
              if (filled == 0) return EINA_FALSE;
           }
         size = size_buffer[i - batch_start].size;
@@ -204,9 +217,10 @@ static Eina_Bool
 _cache_probe(Efl_Ui_Position_Manager_List_Data *pd, unsigned int item)
 {
    int step = 0, max_min = 0;
+   Eina_Bool estimated = EINA_FALSE;
 
    if (item >= pd->cache_size) return EINA_TRUE;
-   if (!_cache_range_ask(pd, item, item + 1, &step, &max_min)) return EINA_FALSE;
+   if (!_cache_range_ask(pd, item, item + 1, &step, &max_min, &estimated)) return EINA_FALSE;
    return (pd->size_cache[item + 1] - pd->size_cache[item]) == step;
 }
 
@@ -263,8 +277,11 @@ _cache_changes_apply(Eo *obj, Efl_Ui_Position_Manager_List_Data *pd)
    int *cache, *steps;
    int max_min = pd->maximum_min_size;
    int old_end, delta;
+   Eina_Bool estimated = EINA_FALSE;
 
    if (pd->size < pd->cache_size) goto full;
+   // Any change may have changed what the provider estimates for the items it was not told of
+   if (pd->estimated) goto full;
 
    if (pd->dirty)
      {
@@ -275,7 +292,7 @@ _cache_changes_apply(Eo *obj, Efl_Ui_Position_Manager_List_Data *pd)
           {
              steps = malloc((to - from) * sizeof (int));
              if (!steps) goto full;
-             if (!_cache_range_ask(pd, from, to, steps, &max_min))
+             if (!_cache_range_ask(pd, from, to, steps, &max_min, &estimated))
                {
                   free(steps);
                   goto full;
@@ -306,7 +323,7 @@ _cache_changes_apply(Eo *obj, Efl_Ui_Position_Manager_List_Data *pd)
      {
         steps = malloc((to - from) * sizeof (int));
         if (!steps) goto full;
-        if (!_cache_range_ask(pd, from, to, steps, &max_min))
+        if (!_cache_range_ask(pd, from, to, steps, &max_min, &estimated))
           {
              free(steps);
              goto full;
@@ -329,6 +346,10 @@ _cache_changes_apply(Eo *obj, Efl_Ui_Position_Manager_List_Data *pd)
      }
 
    pd->maximum_min_size = max_min;
+   if (estimated)
+     {
+        pd->estimated = EINA_TRUE;
+     }
    _cache_checked(obj, pd, dirty_lo, dirty_hi, new_lo, new_hi);
    return;
 
@@ -344,6 +365,12 @@ _cache_item_added(Eo *obj, Efl_Ui_Position_Manager_List_Data *pd, unsigned int i
 
    // Not built: the first build will have the item
    if (!pd->size_cache) return;
+   // What is estimated for the others is not the same with one more
+   if (pd->estimated)
+     {
+        cache_invalidate(obj, pd);
+        return;
+     }
    // Past what the cache has: asked for with the others that came, when it is needed
    if (idx >= pd->cache_size) return;
 
@@ -384,6 +411,12 @@ _cache_item_removed(Eo *obj, Efl_Ui_Position_Manager_List_Data *pd, unsigned int
    unsigned int i;
 
    if (!cache) return;
+   // What is estimated for the others is not the same with one less
+   if (pd->estimated)
+     {
+        cache_invalidate(obj, pd);
+        return;
+     }
    // One of those not asked for yet
    if (idx >= pd->cache_size)
      {
@@ -426,7 +459,8 @@ _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)
+   // Whatever changed, what is estimated for the others did too
+   if (start > end || pd->estimated)
      {
         cache_invalidate(obj, pd);
         return;
diff --git a/src/tests/elementary/efl_ui_test_collection_view.c b/src/tests/elementary/efl_ui_test_collection_view.c
index 96e32149f6..c31fa0fb1f 100644
--- a/src/tests/elementary/efl_ui_test_collection_view.c
+++ b/src/tests/elementary/efl_ui_test_collection_view.c
@@ -1288,6 +1288,182 @@ EFL_START_TEST(test_efl_ui_position_manager_list_cache_shared_size)
 }
 EFL_END_TEST
 
+/* The list position manager, told of every change by a provider whose answers
+   are not the same from one time to the next, must place every item where a
+   manager that is given the final items places it. The provider here gives the
+   rows that nobody measured the average of those that were (so that measuring
+   a row changes the size of all the others, which is not told), and fills only
+   a few rows of what it is asked for at a time. Rows are changed anywhere,
+   added, removed down to none, and measured past the end of the list. */
+#define DIFF_MAX_ROWS 3000
+static unsigned int _diff_measured[DIFF_MAX_ROWS]; // 0: not measured
+static unsigned int _diff_count = 0;
+static unsigned int _diff_cap = 7;
+// Whether the rows nobody measured get the average (and are said to be an estimate), or 40
+static Eina_Bool _diff_estimates = EINA_TRUE;
+
+static Efl_Ui_Position_Manager_Size_Batch_Result
+_diff_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;
+   unsigned int sum = 0, seen = 0, average;
+
+   for (i = 0; i < _diff_count; i++)
+     {
+        if (!_diff_measured[i]) continue;
+        sum += _diff_measured[i];
+        seen++;
+     }
+   average = (seen && _diff_estimates) ? sum / seen : 40;
+
+   for (i = 0; (i < limit) && i < _diff_cap && conf.range.start_id + i < _diff_count; i++)
+     {
+        unsigned int measured = _diff_measured[conf.range.start_id + i];
+
+        sizes[i].size = EINA_SIZE2D(20, measured ? measured : average);
+        sizes[i].element_depth = 0;
+        sizes[i].depth_leader = EINA_FALSE;
+        if (!measured && _diff_estimates) result.estimated = EINA_TRUE;
+     }
+   result.filled_items = i;
+   return result;
+}
+
+static Efl_Ui_Position_Manager_Entity *
+_diff_manager_add(Efl_Ui_Win *win)
+{
+   Efl_Ui_Position_Manager_Entity *manager;
+
+   manager = efl_add(EFL_UI_POSITION_MANAGER_LIST_CLASS, win,
+                     efl_ui_layout_orientation_set(efl_added, EFL_UI_LAYOUT_ORIENTATION_VERTICAL));
+   efl_ui_position_manager_data_access_v1_data_access_set(manager, win, NULL, _cache_object_cb, NULL,
+                                                          NULL, _diff_size_cb, NULL, _diff_count);
+   efl_ui_position_manager_entity_viewport_set(manager, EINA_RECT(0, 0, 100, 1));
+   return manager;
+}
+
+static void
+_diff_check(Efl_Ui_Win *win, Efl_Ui_Position_Manager_Entity *manager, unsigned int step)
+{
+   Efl_Ui_Position_Manager_Entity *fresh;
+   unsigned int i;
+
+   // The job that follows the changes
+   ecore_main_loop_iterate();
+   fresh = _diff_manager_add(win);
+   for (i = 0; i < _diff_count; i++)
+     {
+        Eina_Rect a = efl_ui_position_manager_entity_position_single_item(manager, i);
+        Eina_Rect b = efl_ui_position_manager_entity_position_single_item(fresh, i);
+
+        ck_assert_msg(a.y == b.y, "step %u item %u: y %d against %d", step, i, a.y, b.y);
+        ck_assert_msg(a.h == b.h, "step %u item %u: h %d against %d", step, i, a.h, b.h);
+     }
+   efl_del(fresh);
+}
+
+static void
+_diff_run(unsigned int seed, unsigned int steps, unsigned int range)
+{
+   Efl_Ui_Win *win;
+   Efl_Ui_Position_Manager_Entity *manager;
+   unsigned int i, step;
+
+   win = win_add(NULL, "win", EFL_UI_WIN_TYPE_BASIC);
+   _cache_dummy = efl_add(EFL_UI_BUTTON_CLASS, win);
+   _diff_count = 40;
+   memset(_diff_measured, 0, sizeof (_diff_measured));
+   for (i = 0; i < _diff_count; i += 5)
+     {
+        _diff_measured[i] = 10 + i;
+     }
+   manager = _diff_manager_add(win);
+   _diff_check(win, manager, 0);
+
+   for (step = 1; step <= steps; step++)
+     {
+        unsigned int idx, kind;
+
+        seed = seed * 1103515245 + 12345;
+        // Anywhere in the whole list
+        idx = ((seed >> 8) & 0xffff) % (_diff_count ? _diff_count : 1);
+        seed = seed * 1103515245 + 12345;
+        kind = (seed >> 8) % 12;
+        switch (kind)
+          {
+           case 0:
+           case 1: /* added */
+             {
+                unsigned int at;
+
+                if (_diff_count >= range) break;
+                at = _diff_count ? (idx % (_diff_count + 1)) : 0;
+                memmove(_diff_measured + at + 1, _diff_measured + at,
+                        (_diff_count - at) * sizeof (unsigned int));
+                _diff_measured[at] = (seed >> 20) % 3 ? 0 : 5 + (seed >> 16) % 60;
+                _diff_count++;
+                efl_ui_position_manager_entity_item_added(manager, at, NULL);
+                break;
+             }
+           case 2:
+           case 3: /* removed */
+             {
+                if (!_diff_count) break;
+                memmove(_diff_measured + idx, _diff_measured + idx + 1,
+                        (_diff_count - idx - 1) * sizeof (unsigned int));
+                _diff_count--;
+                efl_ui_position_manager_entity_item_removed(manager, idx, NULL);
+                break;
+             }
+           case 4: /* all removed, then some come */
+             {
+                if ((seed >> 20) % 8) break;
+                while (_diff_count)
+                  {
+                     _diff_count--;
+                     efl_ui_position_manager_entity_item_removed(manager, _diff_count, NULL);
+                  }
+                _diff_check(win, manager, step);
+                for (i = 0; i < 3; i++)
+                  {
+                     _diff_measured[i] = 0;
+                     _diff_count++;
+                     efl_ui_position_manager_entity_item_added(manager, i, NULL);
+                  }
+                break;
+             }
+           case 5: /* told of a change past the end */
+             efl_ui_position_manager_entity_item_size_changed(manager, _diff_count + idx % 3,
+                                                              _diff_count + 2 + idx % 3);
+             break;
+           default: /* measured, and only that row is told, wherever it is */
+             if (!_diff_count) break;
+             _diff_measured[idx] = 5 + (seed >> 16) % 60;
+             efl_ui_position_manager_entity_item_size_changed(manager, idx, idx);
+             break;
+          }
+        if (!((seed >> 20) % 4)) _diff_check(win, manager, step);
+     }
+   _diff_check(win, manager, step);
+   efl_del(manager);
+}
+
+EFL_START_TEST(test_efl_ui_position_manager_list_differential)
+{
+   _diff_estimates = EINA_TRUE;
+   _diff_run(3, 300, 40);
+   // The long list: most of it is far from what changes
+   _diff_run(17, 500, 400);
+   // Answers that only change for the rows that were told of: the cache follows without asking for all
+   _diff_estimates = EINA_FALSE;
+   _diff_run(5, 400, 40);
+   _diff_run(29, 600, 400);
+}
+EFL_END_TEST
+
 /* The groups of the grid position manager follow items that are added or
    removed, with the sizes that are asked for only once: a grid told of every
    change must place every item where a grid that is given the final items
@@ -1664,6 +1840,7 @@ void efl_ui_test_collection_view(TCase *tc)
    tcase_add_test(tc, test_efl_ui_collection_view_many_single_adds);
    tcase_add_test(tc, test_efl_ui_position_manager_list_cache_shared_size);
    tcase_add_test(tc, test_efl_ui_position_manager_list_partial_fill);
+   tcase_add_test(tc, test_efl_ui_position_manager_list_differential);
    tcase_add_test(tc, test_efl_ui_position_manager_grid_groups_follow);
    tcase_add_test(tc, test_efl_ui_collection_view_many_single_adds_idle);
    tcase_add_test(tc, test_efl_ui_collection_view_many_single_adds_grid);

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

Reply via email to