stefan pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=2dcb18acac4d1384e0651d353c2b1f15a8c5e4d4

commit 2dcb18acac4d1384e0651d353c2b1f15a8c5e4d4
Author: Marcel Hollerbach <[email protected]>
Date:   Wed Jun 10 20:48:37 2020 +0200

    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 <[email protected]>
    Differential Revision: https://phab.enlightenment.org/D11997
---
 src/lib/eina/eina_inline_array.x | 11 ++++-------
 1 file 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;

-- 


Reply via email to