summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcel Hollerbach <mail@marcel-hollerbach.de>2020-06-10 20:48:37 +0200
committerStefan Schmidt <s.schmidt@samsung.com>2020-06-25 09:03:09 +0200
commit2dcb18acac4d1384e0651d353c2b1f15a8c5e4d4 (patch)
treef043eadab2f8bae71e5bcdd14f3da28e183e8c5f
parentdc4fd17a9c131d4154b828810fd16231c5968470 (diff)
eina_array: micro optimize eina_array_push
This commit does two things: - Tell the compiler that it is unlikely that we need to grow, and that it is unlikely that data is NULL. Sometimes the if check for data would get dropped out by the compiler when it can be ensured that it is != NULL. However, if we for example efl_add something and eina_push the result, the condition would not be removed, as there is no assertion efl_add would be != NULL. - Do not hide the array assignment in a branch, but make it the default branch, this way instruction cache caches the correct instruction, as branch prediction will now hopefully, due to the hinting, take the correct branch. While benchmarking this here (simply in elementary_perf), this reduced pipeline faults in eina_array_push quite a bit. (Btw. it is hard to track *which* exact calls to eina_array_push do cause that, as mostly this API gets inlined, so it was easier optimizing that, instead of the method arround) Reviewed-by: Stefan Schmidt <stefan@datenfreihafen.org> Differential Revision: https://phab.enlightenment.org/D11997
-rw-r--r--src/lib/eina/eina_inline_array.x11
1 files changed, 4 insertions, 7 deletions
diff --git a/src/lib/eina/eina_inline_array.x b/src/lib/eina/eina_inline_array.x
index 8367d61e7b..a78b674edd 100644
--- a/src/lib/eina/eina_inline_array.x
+++ b/src/lib/eina/eina_inline_array.x
@@ -44,16 +44,13 @@ EAPI Eina_Bool eina_array_grow(Eina_Array *array);
44static inline Eina_Bool 44static inline Eina_Bool
45eina_array_push(Eina_Array *array, const void *data) 45eina_array_push(Eina_Array *array, const void *data)
46{ 46{
47 if (data) 47 if (EINA_UNLIKELY(data == NULL)) return EINA_FALSE;
48 { 48 if (EINA_UNLIKELY((array->count + 1) > array->total)) goto do_grow;
49 if (EINA_UNLIKELY((array->count + 1) > array->total)) goto do_grow;
50do_grow_back: 49do_grow_back:
51 50
52 array->data[array->count++] = (void*) data; 51 array->data[array->count++] = (void*) data;
53 52
54 return EINA_TRUE; 53 return EINA_TRUE;
55 }
56 return EINA_FALSE;
57do_grow: 54do_grow:
58 if (!eina_array_grow(array)) return EINA_FALSE; 55 if (!eina_array_grow(array)) return EINA_FALSE;
59 goto do_grow_back; 56 goto do_grow_back;