summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2014-02-19 10:08:56 +0100
committerJérémy Zurcher <jeremy@asynk.ch>2014-02-26 16:25:00 +0100
commit7821df17dcf20b4f9a17bce9261f7167fa52cd0d (patch)
treecdc690f62dfd4c7f42cb91c0bcdb3012e06d1fbd /src
parent5be3b666b29c4b5d2e4d5a533cdbea5a1ae890ea (diff)
eo: replace composite_objects Eina_List with an array of Eo_Object*
as we don't support multiple composites of the same class, and know at class elaboration how many composites we should have, we can create the composites array and pack it at the end of the object.
Diffstat (limited to 'src')
-rw-r--r--src/lib/eo/Eo.h6
-rw-r--r--src/lib/eo/eo.c85
-rw-r--r--src/lib/eo/eo_private.h12
3 files changed, 71 insertions, 32 deletions
diff --git a/src/lib/eo/Eo.h b/src/lib/eo/Eo.h
index 06a8ca179b..74257ad782 100644
--- a/src/lib/eo/Eo.h
+++ b/src/lib/eo/Eo.h
@@ -938,7 +938,8 @@ EAPI Eina_Bool eo_destructed_is(const Eo *obj);
938 * @param parent the "parent" object. 938 * @param parent the "parent" object.
939 * @return EINA_TRUE if successfull. EINA_FALSE otherwise. 939 * @return EINA_TRUE if successfull. EINA_FALSE otherwise.
940 * 940 *
941 * The class of comp_obj must be part of the extensions of the class of the parent. 941 * The class of comp_obj must be of the type EO_CLASS_TYPE_REGULAR
942 * and be part of the extensions of the class of the parent.
942 * It is not possible to attach more then 1 composite of the same class. 943 * It is not possible to attach more then 1 composite of the same class.
943 * This functions also sets the parent of comp_obj to parent. 944 * This functions also sets the parent of comp_obj to parent.
944 * 945 *
@@ -951,13 +952,14 @@ EAPI Eina_Bool eo_composite_attach(Eo *comp_obj, Eo *parent);
951 * @brief Detach a composite object from another object. 952 * @brief Detach a composite object from another object.
952 * @param comp_obj the object attached to parent. 953 * @param comp_obj the object attached to parent.
953 * @param parent the "parent" object. 954 * @param parent the "parent" object.
955 * @return EINA_TRUE if successfull. EINA_FALSE otherwise.
954 * 956 *
955 * This functions also sets the parent of comp_obj to @c NULL. 957 * This functions also sets the parent of comp_obj to @c NULL.
956 * 958 *
957 * @see eo_composite_attach() 959 * @see eo_composite_attach()
958 * @see eo_composite_is() 960 * @see eo_composite_is()
959 */ 961 */
960EAPI void eo_composite_detach(Eo *comp_obj, Eo *parent); 962EAPI Eina_Bool eo_composite_detach(Eo *comp_obj, Eo *parent);
961 963
962/** 964/**
963 * @brief Check if an object is a composite object. 965 * @brief Check if an object is a composite object.
diff --git a/src/lib/eo/eo.c b/src/lib/eo/eo.c
index 2de799d083..b2cec78794 100644
--- a/src/lib/eo/eo.c
+++ b/src/lib/eo/eo.c
@@ -311,18 +311,19 @@ _eo_op_internal(const char *file, int line, Eo_Base *eo_ptr, const _Eo_Class *cu
311 /* Try composite objects */ 311 /* Try composite objects */
312 if (op_type == EO_OP_TYPE_REGULAR) 312 if (op_type == EO_OP_TYPE_REGULAR)
313 { 313 {
314 Eina_List *itr; 314 const _Eo_Object **comp_itr = ((_Eo_Object *) eo_ptr)->composites;
315 Eo *emb_obj_id; 315 if (!comp_itr) return EINA_FALSE;
316 EINA_LIST_FOREACH(((_Eo_Object *) eo_ptr)->composite_objects, itr, emb_obj_id) 316
317 { 317 for (unsigned int i = 0; i < ((_Eo_Object *) eo_ptr)->klass->composites_count; i++, comp_itr++)
318 /* FIXME: Clean this up a bit. */ 318 if (*comp_itr)
319 EO_OBJ_POINTER_RETURN_VAL(emb_obj_id, emb_obj, EINA_FALSE); 319 {
320 if (_eo_op_internal(file, line, (Eo_Base *) emb_obj, emb_obj->klass, op_type, op, p_list)) 320 if (_eo_op_internal(file, line, (Eo_Base *) (*comp_itr), (*comp_itr)->klass, op_type, op, p_list))
321 { 321 {
322 return EINA_TRUE; 322 return EINA_TRUE;
323 } 323 }
324 } 324 }
325 } 325 }
326
326 return EINA_FALSE; 327 return EINA_FALSE;
327} 328}
328 329
@@ -919,6 +920,8 @@ eo_class_new(const Eo_Class_Description *desc, const Eo_Class *parent_id, ...)
919 EINA_LIST_FREE(extn_list, extn) 920 EINA_LIST_FREE(extn_list, extn)
920 { 921 {
921 *(extn_itr++) = extn; 922 *(extn_itr++) = extn;
923 if (extn->desc->type == EO_CLASS_TYPE_REGULAR)
924 klass->composites_count += 1;
922 925
923 DBG("Added '%s' extension", extn->desc->name); 926 DBG("Added '%s' extension", extn->desc->name);
924 } 927 }
@@ -960,6 +963,8 @@ eo_class_new(const Eo_Class_Description *desc, const Eo_Class *parent_id, ...)
960 } 963 }
961 964
962 klass->obj_size = _eo_sz + extn_data_off; 965 klass->obj_size = _eo_sz + extn_data_off;
966 if (klass->composites_count > 0)
967 klass->obj_size += (klass->composites_count * sizeof(_Eo_Object *));
963 if (getenv("EO_DEBUG")) 968 if (getenv("EO_DEBUG"))
964 { 969 {
965 fprintf(stderr, "Eo class '%s' will take %u bytes per object.\n", 970 fprintf(stderr, "Eo class '%s' will take %u bytes per object.\n",
@@ -1084,6 +1089,10 @@ eo_add_internal(const char *file, int line, const Eo_Class *klass_id, Eo *parent
1084 1089
1085 obj->refcount++; 1090 obj->refcount++;
1086 obj->klass = klass; 1091 obj->klass = klass;
1092 if (klass->composites_count == 0)
1093 obj->composites = NULL;
1094 else
1095 obj->composites = (const _Eo_Object **) ((char *) obj + sizeof(_Eo_Object));
1087 1096
1088#ifndef HAVE_EO_ID 1097#ifndef HAVE_EO_ID
1089 EINA_MAGIC_SET((Eo_Base *) obj, EO_EINA_MAGIC); 1098 EINA_MAGIC_SET((Eo_Base *) obj, EO_EINA_MAGIC);
@@ -1492,39 +1501,65 @@ eo_shutdown(void)
1492EAPI Eina_Bool 1501EAPI Eina_Bool
1493eo_composite_attach(Eo *comp_obj_id, Eo *parent_id) 1502eo_composite_attach(Eo *comp_obj_id, Eo *parent_id)
1494{ 1503{
1504 const _Eo_Object **comp_itr;
1505 const _Eo_Object **comp_dst;
1506
1495 EO_OBJ_POINTER_RETURN_VAL(comp_obj_id, comp_obj, EINA_FALSE); 1507 EO_OBJ_POINTER_RETURN_VAL(comp_obj_id, comp_obj, EINA_FALSE);
1496 EO_OBJ_POINTER_RETURN_VAL(parent_id, parent, EINA_FALSE); 1508 EO_OBJ_POINTER_RETURN_VAL(parent_id, parent, EINA_FALSE);
1497 1509
1498 if (!eo_isa(parent_id, _eo_class_id_get(comp_obj->klass))) return EINA_FALSE; 1510 if (!parent->composites) return EINA_FALSE;
1511
1512 if (comp_obj->klass->desc->type != EO_CLASS_TYPE_REGULAR)
1513 return EINA_FALSE;
1514 if (!eo_isa(parent_id, _eo_class_id_get(comp_obj->klass)))
1515 return EINA_FALSE;
1499 1516
1517 comp_dst = NULL;
1518 comp_itr = parent->composites;
1519 for (unsigned int i = 0; i < parent->klass->composites_count; i++, comp_itr++)
1500 { 1520 {
1501 Eina_List *itr; 1521 if (*comp_itr)
1502 Eo *emb_obj_id;
1503 EINA_LIST_FOREACH(parent->composite_objects, itr, emb_obj_id)
1504 { 1522 {
1505 EO_OBJ_POINTER_RETURN_VAL(emb_obj_id, emb_obj, EINA_FALSE); 1523 if ((*comp_itr)->klass == comp_obj->klass)
1506 if(emb_obj->klass == comp_obj->klass)
1507 return EINA_FALSE; 1524 return EINA_FALSE;
1508 } 1525 }
1526 else if (!comp_dst)
1527 comp_dst = comp_itr;
1509 } 1528 }
1510 1529
1511 comp_obj->composite = EINA_TRUE; 1530 if (!comp_dst)
1512 parent->composite_objects = eina_list_prepend(parent->composite_objects, comp_obj_id); 1531 return EINA_FALSE;
1513 1532
1533 comp_obj->composite = EINA_TRUE;
1534 *comp_dst = comp_obj;
1514 eo_do(comp_obj_id, eo_parent_set(parent_id)); 1535 eo_do(comp_obj_id, eo_parent_set(parent_id));
1515 1536
1516 return EINA_TRUE; 1537 return EINA_TRUE;
1517} 1538}
1518 1539
1519EAPI void 1540EAPI Eina_Bool
1520eo_composite_detach(Eo *comp_obj_id, Eo *parent_id) 1541eo_composite_detach(Eo *comp_obj_id, Eo *parent_id)
1521{ 1542{
1522 EO_OBJ_POINTER_RETURN(comp_obj_id, comp_obj); 1543 const _Eo_Object **comp_itr;
1523 EO_OBJ_POINTER_RETURN(parent_id, parent);
1524 1544
1525 comp_obj->composite = EINA_FALSE; 1545 EO_OBJ_POINTER_RETURN_VAL(comp_obj_id, comp_obj, EINA_FALSE);
1526 parent->composite_objects = eina_list_remove(parent->composite_objects, comp_obj_id); 1546 EO_OBJ_POINTER_RETURN_VAL(parent_id, parent, EINA_FALSE);
1527 eo_do(comp_obj_id, eo_parent_set(NULL)); 1547
1548 if (!parent->composites) return EINA_FALSE;
1549
1550 comp_itr = parent->composites;
1551 for (unsigned int i = 0; i < parent->klass->composites_count; i++, comp_itr++)
1552 {
1553 if (*comp_itr == comp_obj)
1554 {
1555 comp_obj->composite = EINA_FALSE;
1556 *comp_itr = NULL;
1557 eo_do(comp_obj_id, eo_parent_set(NULL));
1558 return EINA_TRUE;
1559 }
1560 }
1561
1562 return EINA_FALSE;
1528} 1563}
1529 1564
1530EAPI Eina_Bool 1565EAPI Eina_Bool
diff --git a/src/lib/eo/eo_private.h b/src/lib/eo/eo_private.h
index 2fd13a9dad..606af23962 100644
--- a/src/lib/eo/eo_private.h
+++ b/src/lib/eo/eo_private.h
@@ -94,7 +94,7 @@ struct _Eo_Object
94 Eina_Inlist *data_xrefs; 94 Eina_Inlist *data_xrefs;
95#endif 95#endif
96 96
97 Eina_List *composite_objects; 97 const _Eo_Object **composites;
98 98
99 int refcount; 99 int refcount;
100 int datarefcount; 100 int datarefcount;
@@ -105,6 +105,7 @@ struct _Eo_Object
105 Eina_Bool composite:1; 105 Eina_Bool composite:1;
106 Eina_Bool del:1; 106 Eina_Bool del:1;
107 Eina_Bool manual_free:1; 107 Eina_Bool manual_free:1;
108 /* [composite*] */
108}; 109};
109 110
110typedef struct _Dich_Chain1 Dich_Chain1; 111typedef struct _Dich_Chain1 Dich_Chain1;
@@ -158,6 +159,7 @@ struct _Eo_Class
158 unsigned int chain_size; 159 unsigned int chain_size;
159 unsigned int base_id; 160 unsigned int base_id;
160 unsigned int data_offset; /* < Offset of the data within object data. */ 161 unsigned int data_offset; /* < Offset of the data within object data. */
162 unsigned int composites_count;
161 163
162 Eina_Bool constructed : 1; 164 Eina_Bool constructed : 1;
163 /* [extensions*] + NULL */ 165 /* [extensions*] + NULL */
@@ -229,11 +231,11 @@ _eo_del_internal(const char *file, int line, _Eo_Object *obj)
229 /*FIXME: add eo_class_unref(klass) ? - just to clear the caches. */ 231 /*FIXME: add eo_class_unref(klass) ? - just to clear the caches. */
230 232
231 { 233 {
232 Eina_List *itr, *itr_n; 234 const _Eo_Object **comp_itr = obj->composites;
233 Eo *emb_obj; 235 for (unsigned int i = 0; i < obj->klass->composites_count; i++, comp_itr++)
234 EINA_LIST_FOREACH_SAFE(obj->composite_objects, itr, itr_n, emb_obj)
235 { 236 {
236 eo_composite_detach(emb_obj, _eo_id_get(obj)); 237 if (*comp_itr)
238 eo_composite_detach(_eo_id_get(*comp_itr), _eo_id_get(obj));
237 } 239 }
238 } 240 }
239 241