diff options
author | Jean Guyomarc'h <jean@guyomarch.bzh> | 2018-01-09 00:03:21 +0100 |
---|---|---|
committer | Jean Guyomarc'h <jean@guyomarch.bzh> | 2018-01-09 00:03:21 +0100 |
commit | 2a32379878ff9e7bc42dcb024777cc9343a03b7c (patch) | |
tree | 901b62637b1b73480e54e7dfa4064bc0323f83e6 | |
parent | af49ee01ab80784037520bc58a77e8c0a1d6acdd (diff) | |
download | efl-2a32379878ff9e7bc42dcb024777cc9343a03b7c.tar.gz |
eo: avoid useless computations
We gained some more frames in the benchmark :)
-rw-r--r-- | src/lib/eo/eo_base_class.c | 79 |
1 files changed, 22 insertions, 57 deletions
diff --git a/src/lib/eo/eo_base_class.c b/src/lib/eo/eo_base_class.c index 32f5c1535e..99d55203a1 100644 --- a/src/lib/eo/eo_base_class.c +++ b/src/lib/eo/eo_base_class.c @@ -997,76 +997,32 @@ struct _Eo_Callback_Description Eina_Bool func_array : 1; }; -static int _eo_callbacks = 0; static Eina_Mempool *_eo_callback_mempool = NULL; -static int _efl_pending_futures = 0; static Eina_Mempool *_efl_pending_future_mempool = NULL; static void -_mempool_data_free(Eina_Mempool **mp, int *usage, void *data) -{ - if (!data) return; - eina_mempool_free(*mp, data); - (*usage)--; - if (*usage == 0) - { - eina_mempool_del(*mp); - *mp = NULL; - } -} - -static void * -_mempool_data_alloc(Eina_Mempool **mp, int *usage, size_t size) -{ - Eo_Callback_Description *cb; - // very unlikely that the mempool isnt initted, so take all the init code - // and move it out of l1 instruction cache space so we dont pollute the - // l1 cache with unused code 99% of the time - if (!*mp) goto init_mempool; -init_mempool_back: - - cb = eina_mempool_calloc(*mp, size); - if (cb) - { - (*usage)++; - return cb; - } - if (*usage != 0) return NULL; - eina_mempool_del(*mp); - *mp = NULL; - return NULL; -init_mempool: - *mp = eina_mempool_add - ("chained_mempool", NULL, NULL, size, 256); - if (!*mp) return NULL; - goto init_mempool_back; -} - -static void _eo_callback_free(Eo_Callback_Description *cb) { - _mempool_data_free(&_eo_callback_mempool, &_eo_callbacks, cb); + eina_mempool_free(_eo_callback_mempool, cb); } static Eo_Callback_Description * _eo_callback_new(void) { - return _mempool_data_alloc(&_eo_callback_mempool, &_eo_callbacks, + return eina_mempool_calloc(_eo_callback_mempool, sizeof(Eo_Callback_Description)); } static void _efl_pending_future_free(Efl_Future_Pending *pending) { - _mempool_data_free(&_efl_pending_future_mempool, - &_efl_pending_futures, pending); + eina_mempool_free(_efl_pending_future_mempool, pending); } static Efl_Future_Pending * _efl_pending_future_new(void) { - return _mempool_data_alloc(&_efl_pending_future_mempool, - &_efl_pending_futures, + return eina_mempool_calloc(_efl_pending_future_mempool, sizeof(Efl_Future_Pending)); } @@ -1236,8 +1192,6 @@ _eo_callbacks_sorted_insert(Efl_Object_Data *pd, Eo_Callback_Description *cb) (pd->callbacks[j]->priority >= cb->priority)) j++; // Increase the callbacks storage by 16 entries at a time - if (_eo_nostep_alloc == -1) _eo_nostep_alloc = !!getenv("EO_NOSTEP_ALLOC"); - if (_eo_nostep_alloc || (pd->callbacks_count & 0xF) == 0x0) { Eo_Callback_Description **tmp; @@ -1247,7 +1201,7 @@ _eo_callbacks_sorted_insert(Efl_Object_Data *pd, Eo_Callback_Description *cb) tmp = realloc(pd->callbacks, new_len * sizeof(Eo_Callback_Description *)); - if (!tmp) return; + if (EINA_UNLIKELY(!tmp)) return; pd->callbacks = tmp; } @@ -1269,7 +1223,7 @@ _eo_callbacks_sorted_insert(Efl_Object_Data *pd, Eo_Callback_Description *cb) } } -static unsigned char +static unsigned short _efl_event_generation(Efl_Object_Data *pd) { if (!pd->event_frame) return 0; @@ -1288,13 +1242,13 @@ _efl_object_event_callback_priority_add(Eo *obj, Efl_Object_Data *pd, Eo_Callback_Description *cb = _eo_callback_new(); // very unlikely so improve l1 instr cache by using goto - if (!cb || !desc || !func) goto err; + if (EINA_UNLIKELY(!cb || !desc || !func)) goto err; cb->items.item.desc = desc; cb->items.item.func = func; cb->func_data = (void *)user_data; cb->priority = priority; cb->generation = _efl_event_generation(pd); - if (!!cb->generation) pd->need_cleaning = EINA_TRUE; + if (cb->generation) pd->need_cleaning = EINA_TRUE; _eo_callbacks_sorted_insert(pd, cb); #ifdef EFL_EVENT_SPECIAL_SKIP @@ -1305,7 +1259,7 @@ _efl_object_event_callback_priority_add(Eo *obj, Efl_Object_Data *pd, return EINA_TRUE; -err: +err: EINA_COLD ERR("Tried adding callback with invalid values: cb: %p desc: %p func: %p", cb, desc, func); _eo_callback_free(cb); return EINA_FALSE; @@ -1472,7 +1426,7 @@ _event_callback_call(Eo *obj_id, Efl_Object_Data *pd, Efl_Event ev; unsigned int idx; Eina_Bool callback_already_stopped, ret; - Efl_Event_Callback_Frame frame; + Efl_Event_Callback_Frame frame = { 0 }; if (pd->callbacks_count == 0) return EINA_FALSE; #ifdef EFL_EVENT_SPECIAL_SKIP @@ -1484,7 +1438,6 @@ _event_callback_call(Eo *obj_id, Efl_Object_Data *pd, (pd->event_cb_efl_event_del_count == 0)) return EINA_FALSE; #endif - memset(&frame, 0, sizeof(Efl_Event_Callback_Frame)); frame.generation = 1; if (pd->event_frame) frame.generation = ((Efl_Event_Callback_Frame*)pd->event_frame)->generation + 1; @@ -2146,11 +2099,23 @@ _efl_object_class_constructor(Efl_Class *klass EINA_UNUSED) { event_freeze_count = 0; _legacy_events_hash = eina_hash_stringshared_new(_legacy_events_hash_free_cb); + + _eo_callback_mempool = + eina_mempool_add("chained_mempool", NULL, NULL, + sizeof(Eo_Callback_Description), 256); + + _efl_pending_future_mempool = + eina_mempool_add("chained_mempool", NULL, NULL, + sizeof(Efl_Future_Pending), 256); + + _eo_nostep_alloc = !!getenv("EO_NOSTEP_ALLOC"); } EOLIAN static void _efl_object_class_destructor(Efl_Class *klass EINA_UNUSED) { + eina_mempool_del(_efl_pending_future_mempool); + eina_mempool_del(_eo_callback_mempool); eina_hash_free(_legacy_events_hash); } |