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
This commit is contained in:
Marcel Hollerbach 2020-06-10 20:48:37 +02:00 committed by Stefan Schmidt
parent dc4fd17a9c
commit 2dcb18acac
1 changed files with 4 additions and 7 deletions

View File

@ -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;