summaryrefslogtreecommitdiff
path: root/legacy/eobj
diff options
context:
space:
mode:
authorTom Hacohen <tom@stosb.com>2012-07-10 14:02:00 +0000
committerTom Hacohen <tom@stosb.com>2012-07-10 14:02:00 +0000
commitb018d8cfcfaf36f43e217d8d51f1e5f631d3d261 (patch)
treec316f4db6d7c049cd700c3c2b815aba45fa49126 /legacy/eobj
parent52d23bf084475e9aa5c8daf8e006b8deacf72a40 (diff)
Eo: eo_do is much faster now.
I simplified the kls-itr code so there'll be less overhead when doing eo_do. SVN revision: 73531
Diffstat (limited to 'legacy/eobj')
-rw-r--r--legacy/eobj/src/lib/eo.c88
1 files changed, 30 insertions, 58 deletions
diff --git a/legacy/eobj/src/lib/eo.c b/legacy/eobj/src/lib/eo.c
index b4f828b697..242007cb58 100644
--- a/legacy/eobj/src/lib/eo.c
+++ b/legacy/eobj/src/lib/eo.c
@@ -25,7 +25,6 @@ static inline void _eo_unref(Eo *obj);
25 25
26typedef struct 26typedef struct
27{ 27{
28 Eo_Op op;
29 const Eo_Class **kls_itr; 28 const Eo_Class **kls_itr;
30} Eo_Kls_Itr; 29} Eo_Kls_Itr;
31 30
@@ -238,26 +237,16 @@ _eo_op_id_name_get(Eo_Op op)
238} 237}
239 238
240static inline void 239static inline void
241_eo_kls_itr_init(const Eo_Class *obj_klass, Eo_Kls_Itr *cur, Eo_Op op, Eo_Kls_Itr *prev_state) 240_eo_kls_itr_init(const Eo_Class *obj_klass, Eo_Kls_Itr *cur, Eo_Kls_Itr *prev_state)
242{ 241{
243 prev_state->op = cur->op;
244 prev_state->kls_itr = cur->kls_itr; 242 prev_state->kls_itr = cur->kls_itr;
245 243 cur->kls_itr = obj_klass->mro;
246 if (cur->op != op)
247 {
248 cur->op = op;
249 cur->kls_itr = obj_klass->mro;
250 }
251} 244}
252 245
253static inline void 246static inline void
254_eo_kls_itr_end(Eo_Kls_Itr *cur, Eo_Kls_Itr *prev_state) 247_eo_kls_itr_end(Eo_Kls_Itr *cur, Eo_Kls_Itr *prev_state)
255{ 248{
256 if (cur->op != prev_state->op) 249 cur->kls_itr = prev_state->kls_itr;
257 {
258 cur->op = prev_state->op;
259 cur->kls_itr = prev_state->kls_itr;
260 }
261} 250}
262 251
263static inline const Eo_Class * 252static inline const Eo_Class *
@@ -267,18 +256,10 @@ _eo_kls_itr_get(Eo_Kls_Itr *cur)
267} 256}
268 257
269static inline const Eo_Class * 258static inline const Eo_Class *
270_eo_kls_itr_next(Eo_Kls_Itr *cur, Eo_Op op) 259_eo_kls_itr_next(Eo_Kls_Itr *cur, Eo_Kls_Itr *prev_state, Eo_Op op)
271{ 260{
272 if (cur->op != op)
273 {
274 Eo_Op node_op = cur->op;
275 ERR("Called with op %x ('%s') while expecting: %x ('%s'). This probaly means you called eo_*_super functions from a wrong place.",
276 op, _eo_op_id_name_get(op),
277 node_op, _eo_op_id_name_get(node_op));
278 return NULL;
279 }
280
281 const Eo_Class **kls_itr = cur->kls_itr; 261 const Eo_Class **kls_itr = cur->kls_itr;
262 prev_state->kls_itr = cur->kls_itr;
282 if (*kls_itr) 263 if (*kls_itr)
283 { 264 {
284 const op_type_funcs *fsrc = _dich_func_get(*kls_itr, op); 265 const op_type_funcs *fsrc = _dich_func_get(*kls_itr, op);
@@ -296,10 +277,9 @@ _eo_kls_itr_next(Eo_Kls_Itr *cur, Eo_Op op)
296} 277}
297 278
298static inline const op_type_funcs * 279static inline const op_type_funcs *
299_eo_kls_itr_func_get(const Eo_Class *klass, Eo_Kls_Itr *mro_itr, Eo_Op op, Eo_Kls_Itr *prev_state) 280_eo_kls_itr_func_get(Eo_Kls_Itr *mro_itr, Eo_Op op)
300{ 281{
301 _eo_kls_itr_init(klass, mro_itr, op, prev_state); 282 const Eo_Class *klass = _eo_kls_itr_get(mro_itr);
302 klass = _eo_kls_itr_get(mro_itr);
303 if (klass) 283 if (klass)
304 { 284 {
305 const op_type_funcs *func = _dich_func_get(klass, op); 285 const op_type_funcs *func = _dich_func_get(klass, op);
@@ -327,8 +307,6 @@ _eo_kls_itr_func_get(const Eo_Class *klass, Eo_Kls_Itr *mro_itr, Eo_Op op, Eo_Kl
327static Eina_Bool 307static Eina_Bool
328_eo_op_internal(Eo *obj, Eo_Op_Type op_type, Eo_Op op, va_list *p_list) 308_eo_op_internal(Eo *obj, Eo_Op_Type op_type, Eo_Op op, va_list *p_list)
329{ 309{
330 Eina_Bool ret = EINA_FALSE;
331
332#ifndef NDEBUG 310#ifndef NDEBUG
333 const Eo_Op_Description *op_desc = _eo_op_id_desc_get(op); 311 const Eo_Op_Description *op_desc = _eo_op_id_desc_get(op);
334 312
@@ -342,16 +320,13 @@ _eo_op_internal(Eo *obj, Eo_Op_Type op_type, Eo_Op op, va_list *p_list)
342 } 320 }
343#endif 321#endif
344 322
345 Eo_Kls_Itr prev_state;
346
347 { 323 {
348 const op_type_funcs *func = 324 const op_type_funcs *func =
349 _eo_kls_itr_func_get(obj->klass, &obj->mro_itr, op, &prev_state); 325 _eo_kls_itr_func_get(&obj->mro_itr, op);
350 if (func) 326 if (func)
351 { 327 {
352 func->func(obj, _eo_data_get(obj, func->src), p_list); 328 func->func(obj, _eo_data_get(obj, func->src), p_list);
353 ret = EINA_TRUE; 329 return EINA_TRUE;
354 goto end;
355 } 330 }
356 } 331 }
357 332
@@ -363,15 +338,11 @@ _eo_op_internal(Eo *obj, Eo_Op_Type op_type, Eo_Op op, va_list *p_list)
363 { 338 {
364 if (_eo_op_internal(emb_obj, op_type, op, p_list)) 339 if (_eo_op_internal(emb_obj, op_type, op, p_list))
365 { 340 {
366 ret = EINA_TRUE; 341 return EINA_TRUE;
367 goto end;
368 } 342 }
369 } 343 }
370 } 344 }
371 345 return EINA_FALSE;
372end:
373 _eo_kls_itr_end(&obj->mro_itr, &prev_state);
374 return ret;
375} 346}
376 347
377EAPI Eina_Bool 348EAPI Eina_Bool
@@ -380,12 +351,14 @@ eo_do_internal(Eo *obj, Eo_Op_Type op_type, ...)
380 Eina_Bool prev_error; 351 Eina_Bool prev_error;
381 Eina_Bool ret = EINA_TRUE; 352 Eina_Bool ret = EINA_TRUE;
382 Eo_Op op = EO_NOOP; 353 Eo_Op op = EO_NOOP;
354 Eo_Kls_Itr prev_state;
383 va_list p_list; 355 va_list p_list;
384 356
385 EO_MAGIC_RETURN_VAL(obj, EO_EINA_MAGIC, EINA_FALSE); 357 EO_MAGIC_RETURN_VAL(obj, EO_EINA_MAGIC, EINA_FALSE);
386 358
387 prev_error = obj->do_error; 359 prev_error = obj->do_error;
388 _eo_ref(obj); 360 _eo_ref(obj);
361 _eo_kls_itr_init(obj->klass, &obj->mro_itr, &prev_state);
389 362
390 va_start(p_list, op_type); 363 va_start(p_list, op_type);
391 364
@@ -410,6 +383,7 @@ eo_do_internal(Eo *obj, Eo_Op_Type op_type, ...)
410 383
411 obj->do_error = prev_error; 384 obj->do_error = prev_error;
412 385
386 _eo_kls_itr_end(&obj->mro_itr, &prev_state);
413 return ret; 387 return ret;
414} 388}
415 389
@@ -419,13 +393,11 @@ eo_do_super_internal(Eo *obj, Eo_Op_Type op_type, Eo_Op op, ...)
419 const Eo_Class *nklass; 393 const Eo_Class *nklass;
420 Eina_Bool ret = EINA_TRUE; 394 Eina_Bool ret = EINA_TRUE;
421 va_list p_list; 395 va_list p_list;
396 Eo_Kls_Itr prev_state;
422 EO_MAGIC_RETURN_VAL(obj, EO_EINA_MAGIC, EINA_FALSE); 397 EO_MAGIC_RETURN_VAL(obj, EO_EINA_MAGIC, EINA_FALSE);
423 398
424 /* Advance the kls itr. */ 399 /* Advance the kls itr. */
425 nklass = _eo_kls_itr_next(&obj->mro_itr, op); 400 nklass = _eo_kls_itr_next(&obj->mro_itr, &prev_state, op);
426
427 if (obj->mro_itr.op != op)
428 return EINA_FALSE;
429 401
430 va_start(p_list, op); 402 va_start(p_list, op);
431 if (!_eo_op_internal(obj, op_type, op, &p_list)) 403 if (!_eo_op_internal(obj, op_type, op, &p_list))
@@ -438,14 +410,13 @@ eo_do_super_internal(Eo *obj, Eo_Op_Type op_type, Eo_Op op, ...)
438 if (obj->do_error) 410 if (obj->do_error)
439 ret = EINA_FALSE; 411 ret = EINA_FALSE;
440 412
413 _eo_kls_itr_end(&obj->mro_itr, &prev_state);
441 return ret; 414 return ret;
442} 415}
443 416
444static Eina_Bool 417static Eina_Bool
445_eo_class_op_internal(Eo_Class *klass, Eo_Op op, va_list *p_list) 418_eo_class_op_internal(Eo_Class *klass, Eo_Op op, va_list *p_list)
446{ 419{
447 Eina_Bool ret = EINA_FALSE;
448
449#ifndef NDEBUG 420#ifndef NDEBUG
450 const Eo_Op_Description *op_desc = _eo_op_id_desc_get(op); 421 const Eo_Op_Description *op_desc = _eo_op_id_desc_get(op);
451 422
@@ -459,22 +430,17 @@ _eo_class_op_internal(Eo_Class *klass, Eo_Op op, va_list *p_list)
459 } 430 }
460#endif 431#endif
461 432
462 Eo_Kls_Itr prev_state;
463
464 { 433 {
465 const op_type_funcs *func = 434 const op_type_funcs *func =
466 _eo_kls_itr_func_get(klass, &klass->mro_itr, op, &prev_state); 435 _eo_kls_itr_func_get(&klass->mro_itr, op);
467 if (func) 436 if (func)
468 { 437 {
469 ((eo_op_func_type_class) func->func)(klass, p_list); 438 ((eo_op_func_type_class) func->func)(klass, p_list);
470 ret = EINA_TRUE; 439 return EINA_TRUE;
471 goto end;
472 } 440 }
473 } 441 }
474 442
475end: 443 return EINA_FALSE;
476 _eo_kls_itr_end(&klass->mro_itr, &prev_state);
477 return ret;
478} 444}
479 445
480EAPI Eina_Bool 446EAPI Eina_Bool
@@ -482,10 +448,13 @@ eo_class_do_internal(const Eo_Class *klass, ...)
482{ 448{
483 Eina_Bool ret = EINA_TRUE; 449 Eina_Bool ret = EINA_TRUE;
484 Eo_Op op = EO_NOOP; 450 Eo_Op op = EO_NOOP;
451 Eo_Kls_Itr prev_state;
485 va_list p_list; 452 va_list p_list;
486 453
487 EO_MAGIC_RETURN_VAL(klass, EO_CLASS_EINA_MAGIC, EINA_FALSE); 454 EO_MAGIC_RETURN_VAL(klass, EO_CLASS_EINA_MAGIC, EINA_FALSE);
488 455
456 _eo_kls_itr_init(klass, &((Eo_Class *) klass)->mro_itr, &prev_state);
457
489 va_start(p_list, klass); 458 va_start(p_list, klass);
490 459
491 op = va_arg(p_list, Eo_Op); 460 op = va_arg(p_list, Eo_Op);
@@ -502,6 +471,7 @@ eo_class_do_internal(const Eo_Class *klass, ...)
502 471
503 va_end(p_list); 472 va_end(p_list);
504 473
474 _eo_kls_itr_end(&((Eo_Class *) klass)->mro_itr, &prev_state);
505 return ret; 475 return ret;
506} 476}
507 477
@@ -511,13 +481,11 @@ eo_class_do_super_internal(const Eo_Class *klass, Eo_Op op, ...)
511 const Eo_Class *nklass; 481 const Eo_Class *nklass;
512 Eina_Bool ret = EINA_TRUE; 482 Eina_Bool ret = EINA_TRUE;
513 va_list p_list; 483 va_list p_list;
484 Eo_Kls_Itr prev_state;
514 EO_MAGIC_RETURN_VAL(klass, EO_CLASS_EINA_MAGIC, EINA_FALSE); 485 EO_MAGIC_RETURN_VAL(klass, EO_CLASS_EINA_MAGIC, EINA_FALSE);
515 486
516 /* Advance the kls itr. */ 487 /* Advance the kls itr. */
517 nklass = _eo_kls_itr_next(&((Eo_Class *) klass)->mro_itr, op); 488 nklass = _eo_kls_itr_next(&((Eo_Class *) klass)->mro_itr, &prev_state, op);
518
519 if (klass->mro_itr.op != op)
520 return EINA_FALSE;
521 489
522 va_start(p_list, op); 490 va_start(p_list, op);
523 if (!_eo_class_op_internal((Eo_Class *) klass, op, &p_list)) 491 if (!_eo_class_op_internal((Eo_Class *) klass, op, &p_list))
@@ -527,6 +495,7 @@ eo_class_do_super_internal(const Eo_Class *klass, Eo_Op op, ...)
527 } 495 }
528 va_end(p_list); 496 va_end(p_list);
529 497
498 _eo_kls_itr_end(&((Eo_Class *) klass)->mro_itr, &prev_state);
530 return ret; 499 return ret;
531} 500}
532 501
@@ -1055,6 +1024,8 @@ eo_class_new(const Eo_Class_Description *desc, Eo_Class_Id id, const Eo_Class *p
1055 } 1024 }
1056 } 1025 }
1057 1026
1027 klass->mro_itr.kls_itr = klass->mro;
1028
1058 _eo_class_constructor(klass); 1029 _eo_class_constructor(klass);
1059 1030
1060 va_end(p_list); 1031 va_end(p_list);
@@ -1136,6 +1107,7 @@ eo_add(const Eo_Class *klass, Eo *parent)
1136 EINA_MAGIC_SET(obj, EO_EINA_MAGIC); 1107 EINA_MAGIC_SET(obj, EO_EINA_MAGIC);
1137 obj->refcount++; 1108 obj->refcount++;
1138 obj->klass = klass; 1109 obj->klass = klass;
1110 obj->mro_itr.kls_itr = obj->klass->mro;
1139 1111
1140 eo_parent_set(obj, parent); 1112 eo_parent_set(obj, parent);
1141 1113