forked from enlightenment/efl
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.
This commit is contained in:
parent
da04400c5d
commit
f736946d10
|
@ -1096,6 +1096,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()
|
||||
|
|
|
@ -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 *
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue