tasn pushed a commit to branch master. http://git.enlightenment.org/core/efl.git/commit/?id=f736946d10d519fe959bef84914e4ca3d91e7db8
commit f736946d10d519fe959bef84914e4ca3d91e7db8 Author: Tom Hacohen <t...@stosb.com> Date: Fri Oct 28 13:19:10 2016 +0100 Eo: Add a method to mark objects for reuse. This informas eo an object is going to get reused/cached, so eo can reset the object appropriately. @feature. --- src/lib/eo/Eo.h | 11 +++++++++++ src/lib/eo/eo.c | 9 ++++++++- src/lib/eo/eo_base_class.c | 4 ++-- src/lib/eo/eo_private.h | 2 +- src/tests/eo/suite/eo_test_general.c | 21 +++++++++++++++++++++ 5 files changed, 43 insertions(+), 4 deletions(-) diff --git a/src/lib/eo/Eo.h b/src/lib/eo/Eo.h index 4ca0713..8c81544 100644 --- a/src/lib/eo/Eo.h +++ b/src/lib/eo/Eo.h @@ -1097,6 +1097,17 @@ EAPI void efl_del_intercept_set(Eo *obj, Efl_Del_Intercept del_intercept_func); EAPI Efl_Del_Intercept efl_del_intercept_get(const Eo *obj); /** + * @brief Clears the object so it can be reused (for example in a cache) + * @param obj The object to mark for reusal + * + * This assumes the destructor has been called on the object, so it + * should probably only be used from the del intercept. + * + * @see efl_del_intercept_set() + */ +EAPI void efl_reuse(const Eo *obj); + +/** * @def efl_xref(obj, ref_obj) * Convenience macro around efl_xref_internal() * @see efl_xref() diff --git a/src/lib/eo/eo.c b/src/lib/eo/eo.c index ad8306d..1da4566 100644 --- a/src/lib/eo/eo.c +++ b/src/lib/eo/eo.c @@ -856,7 +856,7 @@ _efl_add_end(Eo *eo_id, Eina_Bool is_ref, Eina_Bool is_fallback) { efl_ref(eo_id); } - _efl_object_parent_sink(eo_id); + _efl_object_parent_sink_set(eo_id, EINA_TRUE); } if (is_fallback) @@ -867,6 +867,13 @@ _efl_add_end(Eo *eo_id, Eina_Bool is_ref, Eina_Bool is_fallback) return ret; } +EAPI void +efl_reuse(const Eo *_obj) +{ + Eo *obj = (Eo *) _obj; + efl_object_override(obj, NULL); + _efl_object_parent_sink_set(obj, EINA_FALSE); +} /*****************************************************************************/ EAPI const Efl_Class * diff --git a/src/lib/eo/eo_base_class.c b/src/lib/eo/eo_base_class.c index c79d213..5ef3509 100644 --- a/src/lib/eo/eo_base_class.c +++ b/src/lib/eo/eo_base_class.c @@ -535,10 +535,10 @@ _efl_object_del(const Eo *obj, Efl_Object_Data *pd EINA_UNUSED) } void -_efl_object_parent_sink(Eo *obj) +_efl_object_parent_sink_set(Eo *obj, Eina_Bool sink) { Efl_Object_Data *pd = efl_data_scope_get(obj, EFL_OBJECT_CLASS); - pd->parent_sunk = EINA_TRUE; + pd->parent_sunk = sink; } EOLIAN static void diff --git a/src/lib/eo/eo_private.h b/src/lib/eo/eo_private.h index 035d84c..99f667a 100644 --- a/src/lib/eo/eo_private.h +++ b/src/lib/eo/eo_private.h @@ -196,7 +196,7 @@ typedef struct int line; } Eo_Xref_Node; -void _efl_object_parent_sink(Eo *obj); +void _efl_object_parent_sink_set(Eo *obj, Eina_Bool sink); static inline Eo *_eo_header_id_get(const Eo_Header *header) diff --git a/src/tests/eo/suite/eo_test_general.c b/src/tests/eo/suite/eo_test_general.c index bb34b7d..b956eae 100644 --- a/src/tests/eo/suite/eo_test_general.c +++ b/src/tests/eo/suite/eo_test_general.c @@ -1230,6 +1230,12 @@ _del_intercept(Eo *obj) efl_del_intercept_set(obj, NULL); efl_unref(obj); } + +static void +_del_intercept_reuse(Eo *obj) +{ + efl_reuse(obj); +} #endif START_TEST(efl_del_intercept) @@ -1270,6 +1276,21 @@ START_TEST(efl_del_intercept) fail_if(!intercepted); fail_if(efl_isa(obj, klass)); + /* Check reuse works as expected. */ + Eo *parent = efl_add(SIMPLE_CLASS, NULL); + obj = efl_add(klass, NULL); + fail_if(!obj); + ck_assert_int_eq(efl_ref_get(obj), 1); + efl_parent_set(obj, parent); + ck_assert_int_eq(efl_ref_get(obj), 1); + efl_del_intercept_set(obj, _del_intercept_reuse); + efl_del_intercept_set(obj, NULL); + /* This essentially checks it get unsunk */ + ck_assert_int_eq(efl_ref_get(obj), 1); + efl_parent_set(obj, parent); + ck_assert_int_eq(efl_ref_get(obj), 1); + efl_del(obj); + efl_object_shutdown(); #endif } --