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 dc8928dbdce0d50a84ae9de646269320438b07e6
Author: Cedric BAIL <[email protected]>
AuthorDate: Fri Nov 6 01:02:33 2026 -0600

    elementary: binding a layout part to the same factory keeps its content
    
    A factory binds every item again when it hands it out, reused or not.
    For a part already tracked with that same factory, factory_bind unset
    the content, released it and asked the factory for a new one, so the
    content churned on every recycle. Return early instead.
    
    Both that path and the replacement of the factory of a part also leaked
    the extra stringshare reference of the key taken on entry.
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
 src/lib/elementary/efl_ui_layout.c        | 10 +++++++
 src/tests/elementary/efl_ui_test_layout.c | 45 +++++++++++++++++++++++++++++++
 2 files changed, 55 insertions(+)

diff --git a/src/lib/elementary/efl_ui_layout.c b/src/lib/elementary/efl_ui_layout.c
index ec86bd7ed4..acf911d65e 100644
--- a/src/lib/elementary/efl_ui_layout.c
+++ b/src/lib/elementary/efl_ui_layout.c
@@ -2884,6 +2884,13 @@ _efl_ui_layout_base_efl_ui_factory_bind_factory_bind(Eo *obj EINA_UNUSED, Efl_Ui
 
    // First undo the old one if there is one
    tracking = eina_hash_find(pd->connect.factories, ss_key);
+   if (tracking && (tracking->factory == factory))
+     {
+        // Bound again to the same factory, as a factory does for an item it
+        // reuses: the content is already what the factory made.
+        eina_stringshare_del(ss_key);
+        return EINA_ERROR_NO_ERROR;
+     }
    if (tracking)
      {
         Efl_Gfx_Entity *old[1];
@@ -2898,6 +2905,9 @@ _efl_ui_layout_base_efl_ui_factory_bind_factory_bind(Eo *obj EINA_UNUSED, Efl_Ui
 
         // Release previous factory
         efl_replace(&tracking->factory, NULL);
+
+        // The tracking already holds a reference to the key
+        eina_stringshare_del(ss_key);
      }
    else
      {
diff --git a/src/tests/elementary/efl_ui_test_layout.c b/src/tests/elementary/efl_ui_test_layout.c
index 0338532bb9..cf175db265 100644
--- a/src/tests/elementary/efl_ui_test_layout.c
+++ b/src/tests/elementary/efl_ui_test_layout.c
@@ -482,6 +482,50 @@ EFL_START_TEST(efl_ui_layout_calc_subobjs_without_calc)
 }
 EFL_END_TEST
 
+static void
+_building_count(void *data, const Efl_Event *ev EINA_UNUSED)
+{
+   unsigned int *count = data;
+
+   (*count)++;
+}
+
+/* Binding a part again to the factory it is bound to leaves the content it
+ * has: nothing is unset, released or asked of the factory a second time. */
+EFL_START_TEST(efl_ui_layout_test_factory_bind_same_factory)
+{
+   Eo *win = win_add(NULL, "layout", EFL_UI_WIN_TYPE_BASIC);
+   Eo *model = efl_add(EFL_GENERIC_MODEL_CLASS, win);
+   Eo *factory, *item, *content;
+   unsigned int building = 0;
+   int i;
+
+   factory = efl_add(EFL_UI_WIDGET_FACTORY_CLASS, win,
+                     efl_ui_widget_factory_item_class_set(efl_added, EFL_UI_BUTTON_CLASS),
+                     efl_event_callback_add(efl_added, EFL_UI_FACTORY_EVENT_ITEM_BUILDING,
+                                            _building_count, &building));
+   item = efl_add(EFL_UI_LIST_DEFAULT_ITEM_CLASS, win,
+                  efl_ui_view_model_set(efl_added, model));
+
+   efl_ui_factory_bind(item, "icon", factory);
+   for (i = 0; (i < 100) && !efl_content_get(efl_part(item, "icon")); i++)
+     {
+        ecore_main_loop_iterate();
+     }
+   content = efl_content_get(efl_part(item, "icon"));
+   ck_assert_ptr_ne(content, NULL);
+   ck_assert_uint_eq(building, 1);
+
+   efl_ui_factory_bind(item, "icon", factory);
+   for (i = 0; i < 10; i++)
+     {
+        ecore_main_loop_iterate();
+     }
+   ck_assert_ptr_eq(efl_content_get(efl_part(item, "icon")), content);
+   ck_assert_uint_eq(building, 1);
+}
+EFL_END_TEST
+
 void efl_ui_test_layout(TCase *tc)
 {
    tcase_add_test(tc, efl_ui_layout_calc_subobjs_without_calc);
@@ -501,4 +545,5 @@ void efl_ui_test_layout(TCase *tc)
    tcase_add_test(tc, efl_ui_layout_test_property_bind_alone);
    tcase_add_test(tc, efl_ui_layout_test_versioning);
    tcase_add_test(tc, efl_ui_layout_test_freeze);
+   tcase_add_test(tc, efl_ui_layout_test_factory_bind_same_factory);
 }

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

Reply via email to