From 46b3643ff0b4071106bfd8dce975ae0e44200778 Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Fri, 13 Jun 2014 18:09:56 +0100 Subject: [PATCH] Revert "eo: replace composite_objects Eina_List with an array of Eo_Object*" Comp objects are rare, and since we allow using classes as interfaces, we end up allocating a lot of memory for something we don't even use. That's why it was a linked list in the first place, and that's why it should remain a list. This is almost a complete revert. I reverted the code itself, and the intent (use of array instead of list), but not the tests, or the new return value added to comp_detach, which is useful. This reverts commit ef09ef748924c22074e70b97ebc7726fca1513ec. --- src/lib/eo/Eo.h | 3 +- src/lib/eo/eo.c | 65 ++++++++++++----------------------------- src/lib/eo/eo_private.h | 13 ++++----- 3 files changed, 25 insertions(+), 56 deletions(-) diff --git a/src/lib/eo/Eo.h b/src/lib/eo/Eo.h index 116370d401..14728cb13c 100644 --- a/src/lib/eo/Eo.h +++ b/src/lib/eo/Eo.h @@ -874,8 +874,7 @@ EAPI Eina_Bool eo_destructed_is(const Eo *obj); * @param parent the "parent" object. * @return EINA_TRUE if successfull. EINA_FALSE otherwise. * - * The class of comp_obj must be of the type EO_CLASS_TYPE_REGULAR - * and be part of the extensions of the class of the parent. + * The class of comp_obj must be part of the extensions of the class of the parent. * It is not possible to attach more then 1 composite of the same class. * This functions also sets the parent of comp_obj to parent. * diff --git a/src/lib/eo/eo.c b/src/lib/eo/eo.c index f2f0c6acaa..b5aaadf306 100644 --- a/src/lib/eo/eo.c +++ b/src/lib/eo/eo.c @@ -643,12 +643,14 @@ end: /* Try composite objects */ if (is_obj) { - const _Eo_Object **comp_itr = fptr->o.obj->composites; - if (!comp_itr) goto end2; - - for (unsigned int i = 0; i < fptr->o.obj->klass->composites_count; i++, comp_itr++) + Eina_List *itr; + Eo *emb_obj_id; + EINA_LIST_FOREACH(((_Eo_Object *) fptr->o.obj)->composite_objects, itr, emb_obj_id) { - const _Eo_Object *emb_obj = *comp_itr; + _Eo_Object *emb_obj = _eo_obj_pointer_get((Eo_Id)emb_obj_id); + + if (!emb_obj) + goto end2; func = _dich_func_get(emb_obj->klass, op); if (func == NULL) @@ -685,7 +687,6 @@ end2: file, line, func_name, op, main_klass->desc->name); } } - return EINA_FALSE; } @@ -905,11 +906,6 @@ _eo_add_internal_start(const char *file, int line, const Eo_Class *klass_id, Eo obj->refcount++; obj->klass = klass; - if (klass->composites_count == 0) - obj->composites = NULL; - else - obj->composites = (const _Eo_Object **) - ((char *) obj + klass->obj_size - (klass->composites_count * sizeof(_Eo_Object *))); #ifndef HAVE_EO_ID EINA_MAGIC_SET((Eo_Base *) obj, EO_EINA_MAGIC); @@ -1344,8 +1340,6 @@ eo_class_new(const Eo_Class_Description *desc, const Eo_Class *parent_id, ...) EINA_LIST_FREE(extn_list, extn) { *(extn_itr++) = extn; - if (extn->desc->type == EO_CLASS_TYPE_REGULAR) - klass->composites_count += 1; DBG("Added '%s' extension", extn->desc->name); } @@ -1388,8 +1382,6 @@ eo_class_new(const Eo_Class_Description *desc, const Eo_Class *parent_id, ...) } klass->obj_size = _eo_sz + extn_data_off; - if (klass->composites_count > 0) - klass->obj_size += (klass->composites_count * sizeof(_Eo_Object *)); if (getenv("EO_DEBUG")) { fprintf(stderr, "Eo class '%s' will take %u bytes per object.\n", @@ -1858,34 +1850,24 @@ eo_shutdown(void) EAPI Eina_Bool eo_composite_attach(Eo *comp_obj_id, Eo *parent_id) { - const _Eo_Object **comp_itr; - const _Eo_Object **comp_dst; - EO_OBJ_POINTER_RETURN_VAL(comp_obj_id, comp_obj, EINA_FALSE); EO_OBJ_POINTER_RETURN_VAL(parent_id, parent, EINA_FALSE); - if (!parent->composites) return EINA_FALSE; - if (comp_obj->klass->desc->type != EO_CLASS_TYPE_REGULAR) return EINA_FALSE; if (!eo_isa(parent_id, _eo_class_id_get(comp_obj->klass))) return EINA_FALSE; - comp_dst = NULL; - comp_itr = parent->composites; - for (unsigned int i = 0; i < parent->klass->composites_count; i++, comp_itr++) { - if (*comp_itr) + Eina_List *itr; + Eo *emb_obj_id; + EINA_LIST_FOREACH(parent->composite_objects, itr, emb_obj_id) { - if ((*comp_itr)->klass == comp_obj->klass) + EO_OBJ_POINTER_RETURN_VAL(emb_obj_id, emb_obj, EINA_FALSE); + if(emb_obj->klass == comp_obj->klass) return EINA_FALSE; } - else if (!comp_dst) - comp_dst = comp_itr; } - if (!comp_dst) - return EINA_FALSE; - comp_obj->composite = EINA_TRUE; - *comp_dst = comp_obj; + parent->composite_objects = eina_list_prepend(parent->composite_objects, comp_obj_id); eo_do(comp_obj_id, eo_parent_set(parent_id)); @@ -1895,26 +1877,17 @@ eo_composite_attach(Eo *comp_obj_id, Eo *parent_id) EAPI Eina_Bool eo_composite_detach(Eo *comp_obj_id, Eo *parent_id) { - const _Eo_Object **comp_itr; - EO_OBJ_POINTER_RETURN_VAL(comp_obj_id, comp_obj, EINA_FALSE); EO_OBJ_POINTER_RETURN_VAL(parent_id, parent, EINA_FALSE); - if (!parent->composites) return EINA_FALSE; + if (!comp_obj->composite) + return EINA_FALSE; - comp_itr = parent->composites; - for (unsigned int i = 0; i < parent->klass->composites_count; i++, comp_itr++) - { - if (*comp_itr == comp_obj) - { - comp_obj->composite = EINA_FALSE; - *comp_itr = NULL; - eo_do(comp_obj_id, eo_parent_set(NULL)); - return EINA_TRUE; - } - } + comp_obj->composite = EINA_FALSE; + parent->composite_objects = eina_list_remove(parent->composite_objects, comp_obj_id); + eo_do(comp_obj_id, eo_parent_set(NULL)); - return EINA_FALSE; + return EINA_TRUE; } EAPI Eina_Bool diff --git a/src/lib/eo/eo_private.h b/src/lib/eo/eo_private.h index ca643e6ef9..3820a9ca94 100644 --- a/src/lib/eo/eo_private.h +++ b/src/lib/eo/eo_private.h @@ -93,7 +93,7 @@ struct _Eo_Object Eina_Inlist *data_xrefs; #endif - const _Eo_Object **composites; + Eina_List *composite_objects; int refcount; int datarefcount; @@ -104,8 +104,6 @@ struct _Eo_Object Eina_Bool composite:1; Eina_Bool del:1; Eina_Bool manual_free:1; - /* data [parents, self, mixins]*/ - /* [composite*] */ }; /* FIXME: Change the type to something generic that makes sense for eo */ @@ -162,7 +160,6 @@ struct _Eo_Class unsigned int chain_size; unsigned int base_id; unsigned int data_offset; /* < Offset of the data within object data. */ - unsigned int composites_count; Eina_Bool constructed : 1; /* [extensions*] + NULL */ @@ -228,11 +225,11 @@ _eo_del_internal(const char *file, int line, _Eo_Object *obj) /*FIXME: add eo_class_unref(klass) ? - just to clear the caches. */ { - const _Eo_Object **comp_itr = obj->composites; - for (unsigned int i = 0; i < obj->klass->composites_count; i++, comp_itr++) + Eina_List *itr, *itr_n; + Eo *emb_obj; + EINA_LIST_FOREACH_SAFE(obj->composite_objects, itr, itr_n, emb_obj) { - if (*comp_itr) - eo_composite_detach(_eo_id_get(*comp_itr), _eo_id_get(obj)); + eo_composite_detach(emb_obj, _eo_id_get(obj)); } }