From 707f50e680ab4f1861b1e54ca6e2907aaca56c12 Mon Sep 17 00:00:00 2001 From: Adam Jackson Date: Tue, 15 May 2018 12:55:55 -0400 Subject: dispatch: Try harder to avoid calling the resolver Our caller may load (eg) epoxy_glAlphaFunc, which is a function pointer, and then call through that value multiple times. Until the caller re-examines the value of that function pointer, which is a copy relocation in the executable, repeated calls mean repeated work resolving the GL function. We can't make the caller reinspect the variable, but the resolver function can avoid doing redundant work. Fixes: anholt/libepoxy#171 Signed-off-by: Adam Jackson --- src/dispatch_common.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/dispatch_common.h b/src/dispatch_common.h index fc99635..dcb3a35 100644 --- a/src/dispatch_common.h +++ b/src/dispatch_common.h @@ -85,10 +85,11 @@ #define WRAPPER(x) x ## _wrapped #define GEN_GLOBAL_REWRITE_PTR(name, args, passthrough) \ - static void EPOXY_CALLSPEC \ + static void EPOXY_CALLSPEC \ name##_global_rewrite_ptr args \ { \ - name = (void *)name##_resolver(); \ + if (name == (void *)name##_global_rewrite_ptr) \ + name = (void *)name##_resolver(); \ name passthrough; \ } @@ -96,7 +97,8 @@ static ret EPOXY_CALLSPEC \ name##_global_rewrite_ptr args \ { \ - name = (void *)name##_resolver(); \ + if (name == (void *)name##_global_rewrite_ptr) \ + name = (void *)name##_resolver(); \ return name passthrough; \ } -- cgit v1.2.1