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)
downloadefl-2dcb18acac4d1384e0651d353c2b1f15a8c5e4d4.tar.gz
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);
static inline Eina_Bool
eina_array_push(Eina_Array *array, const void *data)
{
- if (data)
- {
- if (EINA_UNLIKELY((array->count + 1) > array->total)) goto do_grow;
+ if (EINA_UNLIKELY(data == NULL)) return EINA_FALSE;
+ if (EINA_UNLIKELY((array->count + 1) > array->total)) goto do_grow;
do_grow_back:
- array->data[array->count++] = (void*) data;
+ array->data[array->count++] = (void*) data;
- return EINA_TRUE;
- }
- return EINA_FALSE;
+ return EINA_TRUE;
do_grow:
if (!eina_array_grow(array)) return EINA_FALSE;
goto do_grow_back;