summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean Guyomarc'h <jean@guyomarch.bzh>2018-01-09 00:03:21 +0100
committerJean Guyomarc'h <jean@guyomarch.bzh>2018-01-09 00:03:21 +0100
commit2a32379878ff9e7bc42dcb024777cc9343a03b7c (patch)
tree901b62637b1b73480e54e7dfa4064bc0323f83e6
parentaf49ee01ab80784037520bc58a77e8c0a1d6acdd (diff)
eo: avoid useless computations
We gained some more frames in the benchmark :)
-rw-r--r--src/lib/eo/eo_base_class.c79
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
997 Eina_Bool func_array : 1; 997 Eina_Bool func_array : 1;
998}; 998};
999 999
1000static int _eo_callbacks = 0;
1001static Eina_Mempool *_eo_callback_mempool = NULL; 1000static Eina_Mempool *_eo_callback_mempool = NULL;
1002static int _efl_pending_futures = 0;
1003static Eina_Mempool *_efl_pending_future_mempool = NULL; 1001static Eina_Mempool *_efl_pending_future_mempool = NULL;
1004 1002
1005static void 1003static void
1006_mempool_data_free(Eina_Mempool **mp, int *usage, void *data)
1007{
1008 if (!data) return;
1009 eina_mempool_free(*mp, data);
1010 (*usage)--;
1011 if (*usage == 0)
1012 {
1013 eina_mempool_del(*mp);
1014 *mp = NULL;
1015 }
1016}
1017
1018static void *
1019_mempool_data_alloc(Eina_Mempool **mp, int *usage, size_t size)
1020{
1021 Eo_Callback_Description *cb;
1022 // very unlikely that the mempool isnt initted, so take all the init code
1023 // and move it out of l1 instruction cache space so we dont pollute the
1024 // l1 cache with unused code 99% of the time
1025 if (!*mp) goto init_mempool;
1026init_mempool_back:
1027
1028 cb = eina_mempool_calloc(*mp, size);
1029 if (cb)
1030 {
1031 (*usage)++;
1032 return cb;
1033 }
1034 if (*usage != 0) return NULL;
1035 eina_mempool_del(*mp);
1036 *mp = NULL;
1037 return NULL;
1038init_mempool:
1039 *mp = eina_mempool_add
1040 ("chained_mempool", NULL, NULL, size, 256);
1041 if (!*mp) return NULL;
1042 goto init_mempool_back;
1043}
1044
1045static void
1046_eo_callback_free(Eo_Callback_Description *cb) 1004_eo_callback_free(Eo_Callback_Description *cb)
1047{ 1005{
1048 _mempool_data_free(&_eo_callback_mempool, &_eo_callbacks, cb); 1006 eina_mempool_free(_eo_callback_mempool, cb);
1049} 1007}
1050 1008
1051static Eo_Callback_Description * 1009static Eo_Callback_Description *
1052_eo_callback_new(void) 1010_eo_callback_new(void)
1053{ 1011{
1054 return _mempool_data_alloc(&_eo_callback_mempool, &_eo_callbacks, 1012 return eina_mempool_calloc(_eo_callback_mempool,
1055 sizeof(Eo_Callback_Description)); 1013 sizeof(Eo_Callback_Description));
1056} 1014}
1057 1015
1058static void 1016static void
1059_efl_pending_future_free(Efl_Future_Pending *pending) 1017_efl_pending_future_free(Efl_Future_Pending *pending)
1060{ 1018{
1061 _mempool_data_free(&_efl_pending_future_mempool, 1019 eina_mempool_free(_efl_pending_future_mempool, pending);
1062 &_efl_pending_futures, pending);
1063} 1020}
1064 1021
1065static Efl_Future_Pending * 1022static Efl_Future_Pending *
1066_efl_pending_future_new(void) 1023_efl_pending_future_new(void)
1067{ 1024{
1068 return _mempool_data_alloc(&_efl_pending_future_mempool, 1025 return eina_mempool_calloc(_efl_pending_future_mempool,
1069 &_efl_pending_futures,
1070 sizeof(Efl_Future_Pending)); 1026 sizeof(Efl_Future_Pending));
1071} 1027}
1072 1028
@@ -1236,8 +1192,6 @@ _eo_callbacks_sorted_insert(Efl_Object_Data *pd, Eo_Callback_Description *cb)
1236 (pd->callbacks[j]->priority >= cb->priority)) j++; 1192 (pd->callbacks[j]->priority >= cb->priority)) j++;
1237 1193
1238 // Increase the callbacks storage by 16 entries at a time 1194 // Increase the callbacks storage by 16 entries at a time
1239 if (_eo_nostep_alloc == -1) _eo_nostep_alloc = !!getenv("EO_NOSTEP_ALLOC");
1240
1241 if (_eo_nostep_alloc || (pd->callbacks_count & 0xF) == 0x0) 1195 if (_eo_nostep_alloc || (pd->callbacks_count & 0xF) == 0x0)
1242 { 1196 {
1243 Eo_Callback_Description **tmp; 1197 Eo_Callback_Description **tmp;
@@ -1247,7 +1201,7 @@ _eo_callbacks_sorted_insert(Efl_Object_Data *pd, Eo_Callback_Description *cb)
1247 1201
1248 tmp = realloc(pd->callbacks, 1202 tmp = realloc(pd->callbacks,
1249 new_len * sizeof(Eo_Callback_Description *)); 1203 new_len * sizeof(Eo_Callback_Description *));
1250 if (!tmp) return; 1204 if (EINA_UNLIKELY(!tmp)) return;
1251 pd->callbacks = tmp; 1205 pd->callbacks = tmp;
1252 } 1206 }
1253 1207
@@ -1269,7 +1223,7 @@ _eo_callbacks_sorted_insert(Efl_Object_Data *pd, Eo_Callback_Description *cb)
1269 } 1223 }
1270} 1224}
1271 1225
1272static unsigned char 1226static unsigned short
1273_efl_event_generation(Efl_Object_Data *pd) 1227_efl_event_generation(Efl_Object_Data *pd)
1274{ 1228{
1275 if (!pd->event_frame) return 0; 1229 if (!pd->event_frame) return 0;
@@ -1288,13 +1242,13 @@ _efl_object_event_callback_priority_add(Eo *obj, Efl_Object_Data *pd,
1288 Eo_Callback_Description *cb = _eo_callback_new(); 1242 Eo_Callback_Description *cb = _eo_callback_new();
1289 1243
1290 // very unlikely so improve l1 instr cache by using goto 1244 // very unlikely so improve l1 instr cache by using goto
1291 if (!cb || !desc || !func) goto err; 1245 if (EINA_UNLIKELY(!cb || !desc || !func)) goto err;
1292 cb->items.item.desc = desc; 1246 cb->items.item.desc = desc;
1293 cb->items.item.func = func; 1247 cb->items.item.func = func;
1294 cb->func_data = (void *)user_data; 1248 cb->func_data = (void *)user_data;
1295 cb->priority = priority; 1249 cb->priority = priority;
1296 cb->generation = _efl_event_generation(pd); 1250 cb->generation = _efl_event_generation(pd);
1297 if (!!cb->generation) pd->need_cleaning = EINA_TRUE; 1251 if (cb->generation) pd->need_cleaning = EINA_TRUE;
1298 1252
1299 _eo_callbacks_sorted_insert(pd, cb); 1253 _eo_callbacks_sorted_insert(pd, cb);
1300#ifdef EFL_EVENT_SPECIAL_SKIP 1254#ifdef EFL_EVENT_SPECIAL_SKIP
@@ -1305,7 +1259,7 @@ _efl_object_event_callback_priority_add(Eo *obj, Efl_Object_Data *pd,
1305 1259
1306 return EINA_TRUE; 1260 return EINA_TRUE;
1307 1261
1308err: 1262err: EINA_COLD
1309 ERR("Tried adding callback with invalid values: cb: %p desc: %p func: %p", cb, desc, func); 1263 ERR("Tried adding callback with invalid values: cb: %p desc: %p func: %p", cb, desc, func);
1310 _eo_callback_free(cb); 1264 _eo_callback_free(cb);
1311 return EINA_FALSE; 1265 return EINA_FALSE;
@@ -1472,7 +1426,7 @@ _event_callback_call(Eo *obj_id, Efl_Object_Data *pd,
1472 Efl_Event ev; 1426 Efl_Event ev;
1473 unsigned int idx; 1427 unsigned int idx;
1474 Eina_Bool callback_already_stopped, ret; 1428 Eina_Bool callback_already_stopped, ret;
1475 Efl_Event_Callback_Frame frame; 1429 Efl_Event_Callback_Frame frame = { 0 };
1476 1430
1477 if (pd->callbacks_count == 0) return EINA_FALSE; 1431 if (pd->callbacks_count == 0) return EINA_FALSE;
1478#ifdef EFL_EVENT_SPECIAL_SKIP 1432#ifdef EFL_EVENT_SPECIAL_SKIP
@@ -1484,7 +1438,6 @@ _event_callback_call(Eo *obj_id, Efl_Object_Data *pd,
1484 (pd->event_cb_efl_event_del_count == 0)) return EINA_FALSE; 1438 (pd->event_cb_efl_event_del_count == 0)) return EINA_FALSE;
1485#endif 1439#endif
1486 1440
1487 memset(&frame, 0, sizeof(Efl_Event_Callback_Frame));
1488 frame.generation = 1; 1441 frame.generation = 1;
1489 if (pd->event_frame) 1442 if (pd->event_frame)
1490 frame.generation = ((Efl_Event_Callback_Frame*)pd->event_frame)->generation + 1; 1443 frame.generation = ((Efl_Event_Callback_Frame*)pd->event_frame)->generation + 1;
@@ -2146,11 +2099,23 @@ _efl_object_class_constructor(Efl_Class *klass EINA_UNUSED)
2146{ 2099{
2147 event_freeze_count = 0; 2100 event_freeze_count = 0;
2148 _legacy_events_hash = eina_hash_stringshared_new(_legacy_events_hash_free_cb); 2101 _legacy_events_hash = eina_hash_stringshared_new(_legacy_events_hash_free_cb);
2102
2103 _eo_callback_mempool =
2104 eina_mempool_add("chained_mempool", NULL, NULL,
2105 sizeof(Eo_Callback_Description), 256);
2106
2107 _efl_pending_future_mempool =
2108 eina_mempool_add("chained_mempool", NULL, NULL,
2109 sizeof(Efl_Future_Pending), 256);
2110
2111 _eo_nostep_alloc = !!getenv("EO_NOSTEP_ALLOC");
2149} 2112}
2150 2113
2151EOLIAN static void 2114EOLIAN static void
2152_efl_object_class_destructor(Efl_Class *klass EINA_UNUSED) 2115_efl_object_class_destructor(Efl_Class *klass EINA_UNUSED)
2153{ 2116{
2117 eina_mempool_del(_efl_pending_future_mempool);
2118 eina_mempool_del(_eo_callback_mempool);
2154 eina_hash_free(_legacy_events_hash); 2119 eina_hash_free(_legacy_events_hash);
2155} 2120}
2156 2121