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-02-25 14:06:52 +0100
commit91966f1d16072e2a910d60e16ee9f9d39148914e (patch)
treebe50a55e142612aa0372c3a2ec3cb79c004f3360
parent088f9b862f4e14e7a0528cd2c5e7a541be2df7af (diff)
eo: avoid useless computations
Better exploit class constructor and destructor to initialize data once and for all. This allows not make initialization checks at runtime.
-rw-r--r--src/lib/eo/eo_base_class.c85
1 files changed, 27 insertions, 58 deletions
diff --git a/src/lib/eo/eo_base_class.c b/src/lib/eo/eo_base_class.c
index a5295fa373..ca38e7b171 100644
--- a/src/lib/eo/eo_base_class.c
+++ b/src/lib/eo/eo_base_class.c
@@ -984,76 +984,32 @@ struct _Eo_Callback_Description
984 Eina_Bool func_array : 1; 984 Eina_Bool func_array : 1;
985}; 985};
986 986
987static int _eo_callbacks = 0;
988static Eina_Mempool *_eo_callback_mempool = NULL; 987static Eina_Mempool *_eo_callback_mempool = NULL;
989static int _efl_pending_futures = 0;
990static Eina_Mempool *_efl_pending_future_mempool = NULL; 988static Eina_Mempool *_efl_pending_future_mempool = NULL;
991 989
992static void 990static void
993_mempool_data_free(Eina_Mempool **mp, int *usage, void *data)
994{
995 if (!data) return;
996 eina_mempool_free(*mp, data);
997 (*usage)--;
998 if (*usage == 0)
999 {
1000 eina_mempool_del(*mp);
1001 *mp = NULL;
1002 }
1003}
1004
1005static void *
1006_mempool_data_alloc(Eina_Mempool **mp, int *usage, size_t size)
1007{
1008 Eo_Callback_Description *cb;
1009 // very unlikely that the mempool isnt initted, so take all the init code
1010 // and move it out of l1 instruction cache space so we dont pollute the
1011 // l1 cache with unused code 99% of the time
1012 if (!*mp) goto init_mempool;
1013init_mempool_back:
1014
1015 cb = eina_mempool_calloc(*mp, size);
1016 if (cb)
1017 {
1018 (*usage)++;
1019 return cb;
1020 }
1021 if (*usage != 0) return NULL;
1022 eina_mempool_del(*mp);
1023 *mp = NULL;
1024 return NULL;
1025init_mempool:
1026 *mp = eina_mempool_add
1027 ("chained_mempool", NULL, NULL, size, 256);
1028 if (!*mp) return NULL;
1029 goto init_mempool_back;
1030}
1031
1032static void
1033_eo_callback_free(Eo_Callback_Description *cb) 991_eo_callback_free(Eo_Callback_Description *cb)
1034{ 992{
1035 _mempool_data_free(&_eo_callback_mempool, &_eo_callbacks, cb); 993 eina_mempool_free(_eo_callback_mempool, cb);
1036} 994}
1037 995
1038static Eo_Callback_Description * 996static Eo_Callback_Description *
1039_eo_callback_new(void) 997_eo_callback_new(void)
1040{ 998{
1041 return _mempool_data_alloc(&_eo_callback_mempool, &_eo_callbacks, 999 return eina_mempool_calloc(_eo_callback_mempool,
1042 sizeof(Eo_Callback_Description)); 1000 sizeof(Eo_Callback_Description));
1043} 1001}
1044 1002
1045static void 1003static void
1046_efl_pending_future_free(Efl_Future_Pending *pending) 1004_efl_pending_future_free(Efl_Future_Pending *pending)
1047{ 1005{
1048 _mempool_data_free(&_efl_pending_future_mempool, 1006 eina_mempool_free(_efl_pending_future_mempool, pending);
1049 &_efl_pending_futures, pending);
1050} 1007}
1051 1008
1052static Efl_Future_Pending * 1009static Efl_Future_Pending *
1053_efl_pending_future_new(void) 1010_efl_pending_future_new(void)
1054{ 1011{
1055 return _mempool_data_alloc(&_efl_pending_future_mempool, 1012 return eina_mempool_calloc(_efl_pending_future_mempool,
1056 &_efl_pending_futures,
1057 sizeof(Efl_Future_Pending)); 1013 sizeof(Efl_Future_Pending));
1058} 1014}
1059 1015
@@ -1226,8 +1182,6 @@ _eo_callbacks_sorted_insert(Efl_Object_Data *pd, Eo_Callback_Description *cb)
1226 (pd->callbacks[j]->priority >= cb->priority)) j++; 1182 (pd->callbacks[j]->priority >= cb->priority)) j++;
1227 1183
1228 // Increase the callbacks storage by 16 entries at a time 1184 // Increase the callbacks storage by 16 entries at a time
1229 if (_eo_nostep_alloc == -1) _eo_nostep_alloc = !!getenv("EO_NOSTEP_ALLOC");
1230
1231 if (_eo_nostep_alloc || (pd->callbacks_count & 0xF) == 0x0) 1185 if (_eo_nostep_alloc || (pd->callbacks_count & 0xF) == 0x0)
1232 { 1186 {
1233 Eo_Callback_Description **tmp; 1187 Eo_Callback_Description **tmp;
@@ -1237,7 +1191,7 @@ _eo_callbacks_sorted_insert(Efl_Object_Data *pd, Eo_Callback_Description *cb)
1237 1191
1238 tmp = realloc(pd->callbacks, 1192 tmp = realloc(pd->callbacks,
1239 new_len * sizeof(Eo_Callback_Description *)); 1193 new_len * sizeof(Eo_Callback_Description *));
1240 if (!tmp) return; 1194 if (EINA_UNLIKELY(!tmp)) return;
1241 pd->callbacks = tmp; 1195 pd->callbacks = tmp;
1242 } 1196 }
1243 1197
@@ -1259,7 +1213,7 @@ _eo_callbacks_sorted_insert(Efl_Object_Data *pd, Eo_Callback_Description *cb)
1259 } 1213 }
1260} 1214}
1261 1215
1262static unsigned char 1216static unsigned short
1263_efl_event_generation(Efl_Object_Data *pd) 1217_efl_event_generation(Efl_Object_Data *pd)
1264{ 1218{
1265 if (!pd->event_frame) return 0; 1219 if (!pd->event_frame) return 0;
@@ -1278,13 +1232,13 @@ _efl_object_event_callback_priority_add(Eo *obj, Efl_Object_Data *pd,
1278 Eo_Callback_Description *cb = _eo_callback_new(); 1232 Eo_Callback_Description *cb = _eo_callback_new();
1279 1233
1280 // very unlikely so improve l1 instr cache by using goto 1234 // very unlikely so improve l1 instr cache by using goto
1281 if (!cb || !desc || !func) goto err; 1235 if (EINA_UNLIKELY(!cb || !desc || !func)) goto err;
1282 cb->items.item.desc = desc; 1236 cb->items.item.desc = desc;
1283 cb->items.item.func = func; 1237 cb->items.item.func = func;
1284 cb->func_data = (void *)user_data; 1238 cb->func_data = (void *)user_data;
1285 cb->priority = priority; 1239 cb->priority = priority;
1286 cb->generation = _efl_event_generation(pd); 1240 cb->generation = _efl_event_generation(pd);
1287 if (!!cb->generation) pd->need_cleaning = EINA_TRUE; 1241 if (cb->generation) pd->need_cleaning = EINA_TRUE;
1288 1242
1289 _eo_callbacks_sorted_insert(pd, cb); 1243 _eo_callbacks_sorted_insert(pd, cb);
1290#ifdef EFL_EVENT_SPECIAL_SKIP 1244#ifdef EFL_EVENT_SPECIAL_SKIP
@@ -1297,7 +1251,7 @@ _efl_object_event_callback_priority_add(Eo *obj, Efl_Object_Data *pd,
1297 1251
1298 return EINA_TRUE; 1252 return EINA_TRUE;
1299 1253
1300err: 1254err: EINA_COLD
1301 ERR("Tried adding callback with invalid values: cb: %p desc: %p func: %p", cb, desc, func); 1255 ERR("Tried adding callback with invalid values: cb: %p desc: %p func: %p", cb, desc, func);
1302 _eo_callback_free(cb); 1256 _eo_callback_free(cb);
1303 return EINA_FALSE; 1257 return EINA_FALSE;
@@ -1474,7 +1428,12 @@ _event_callback_call(Eo *obj_id, Efl_Object_Data *pd,
1474 Efl_Event ev; 1428 Efl_Event ev;
1475 unsigned int idx; 1429 unsigned int idx;
1476 Eina_Bool callback_already_stopped, ret; 1430 Eina_Bool callback_already_stopped, ret;
1477 Efl_Event_Callback_Frame frame; 1431 Efl_Event_Callback_Frame frame = {
1432 .next = NULL,
1433 .idx = 0,
1434 .inserted_before = 0,
1435 .generation = 1,
1436 };
1478 1437
1479 if (pd->callbacks_count == 0) return EINA_FALSE; 1438 if (pd->callbacks_count == 0) return EINA_FALSE;
1480#ifdef EFL_EVENT_SPECIAL_SKIP 1439#ifdef EFL_EVENT_SPECIAL_SKIP
@@ -1486,8 +1445,6 @@ _event_callback_call(Eo *obj_id, Efl_Object_Data *pd,
1486 (pd->event_cb_efl_event_del_count == 0)) return EINA_FALSE; 1445 (pd->event_cb_efl_event_del_count == 0)) return EINA_FALSE;
1487#endif 1446#endif
1488 1447
1489 memset(&frame, 0, sizeof(Efl_Event_Callback_Frame));
1490 frame.generation = 1;
1491 if (pd->event_frame) 1448 if (pd->event_frame)
1492 frame.generation = ((Efl_Event_Callback_Frame*)pd->event_frame)->generation + 1; 1449 frame.generation = ((Efl_Event_Callback_Frame*)pd->event_frame)->generation + 1;
1493 1450
@@ -2151,11 +2108,23 @@ _efl_object_class_constructor(Efl_Class *klass EINA_UNUSED)
2151{ 2108{
2152 event_freeze_count = 0; 2109 event_freeze_count = 0;
2153 _legacy_events_hash = eina_hash_stringshared_new(_legacy_events_hash_free_cb); 2110 _legacy_events_hash = eina_hash_stringshared_new(_legacy_events_hash_free_cb);
2111
2112 _eo_callback_mempool =
2113 eina_mempool_add("chained_mempool", NULL, NULL,
2114 sizeof(Eo_Callback_Description), 256);
2115
2116 _efl_pending_future_mempool =
2117 eina_mempool_add("chained_mempool", NULL, NULL,
2118 sizeof(Efl_Future_Pending), 256);
2119
2120 _eo_nostep_alloc = !!getenv("EO_NOSTEP_ALLOC");
2154} 2121}
2155 2122
2156EOLIAN static void 2123EOLIAN static void
2157_efl_object_class_destructor(Efl_Class *klass EINA_UNUSED) 2124_efl_object_class_destructor(Efl_Class *klass EINA_UNUSED)
2158{ 2125{
2126 eina_mempool_del(_efl_pending_future_mempool);
2127 eina_mempool_del(_eo_callback_mempool);
2159 eina_hash_free(_legacy_events_hash); 2128 eina_hash_free(_legacy_events_hash);
2160} 2129}
2161 2130