From 0ec2ced815134915f60b2c6adec1ccf9562b3938 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Andre Date: Fri, 6 Nov 2015 18:34:50 +0900 Subject: Eina: Micro-optimize eina_main_loop_is Since this is called a crazy number of times with Eo, it would be good to have the fastest solution possible. pthread_equal costs about twice as much as pthread_self() even though it can safely be emulated with == Valgrind reports a drop from ~3.2% to ~1.5% of all instructions. --- src/lib/eina/eina_main.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/lib/eina/eina_main.c b/src/lib/eina/eina_main.c index 1daa795e87..ffb017767e 100644 --- a/src/lib/eina/eina_main.c +++ b/src/lib/eina/eina_main.c @@ -416,7 +416,13 @@ EAPI Eina_Bool eina_main_loop_is(void) { #ifdef EFL_HAVE_THREADS - if (pthread_equal(_eina_main_loop, pthread_self())) +# ifdef __GNUC__ + /* pthread_self() can't be optimized, it's a single asm "movl" */ + if (__builtin_types_compatible_p(pthread_t, unsigned long int)) + return (pthread_self() == _eina_main_loop); + else +# endif + if (pthread_equal(_eina_main_loop, pthread_self())) return EINA_TRUE; #endif return EINA_FALSE; -- cgit v1.2.1