diff options
author | Tom Hacohen <tom@stosb.com> | 2016-10-28 13:19:10 +0100 |
---|---|---|
committer | Tom Hacohen <tom@stosb.com> | 2016-10-28 13:19:10 +0100 |
commit | f736946d10d519fe959bef84914e4ca3d91e7db8 (patch) | |
tree | 7ca64ac9ad4c0ad57cf8ea322bcb7f687688e40c | |
parent | da04400c5d22aac0888ceb945c0afe28459af06c (diff) | |
download | efl-f736946d10d519fe959bef84914e4ca3d91e7db8.tar.gz |
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.
-rw-r--r-- | src/lib/eo/Eo.h | 11 | ||||
-rw-r--r-- | src/lib/eo/eo.c | 9 | ||||
-rw-r--r-- | src/lib/eo/eo_base_class.c | 4 | ||||
-rw-r--r-- | src/lib/eo/eo_private.h | 2 | ||||
-rw-r--r-- | 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 4ca0713f60..8c815447c3 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 ad8306db4b..1da45664e6 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 c79d213974..5ef35092de 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 035d84ceda..99f667a62b 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 bb34b7dd98..b956eae53e 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 } |