From 76c4873e8cad2871d2d547318d371b9a89d8c806 Mon Sep 17 00:00:00 2001 From: Ebrahim Byagowi Date: Fri, 2 Jun 2017 21:53:10 +0430 Subject: [PATCH] Support branch prediction helpers on clang compiles (#491) --- src/hb-private.hh | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/hb-private.hh b/src/hb-private.hh index 3595edee3..b5dccc556 100644 --- a/src/hb-private.hh +++ b/src/hb-private.hh @@ -74,10 +74,9 @@ extern "C" void hb_free_impl(void *ptr); /* Compiler attributes */ -#if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__) -#define _HB_BOOLEAN_EXPR(expr) ((expr) ? 1 : 0) -#define likely(expr) (__builtin_expect (_HB_BOOLEAN_EXPR(expr), 1)) -#define unlikely(expr) (__builtin_expect (_HB_BOOLEAN_EXPR(expr), 0)) +#if (defined(__GNUC__) || defined(__clang__)) && defined(__OPTIMIZE__) +#define likely(expr) (__builtin_expect (!!(expr), 1)) +#define unlikely(expr) (__builtin_expect (!!(expr), 0)) #else #define likely(expr) (expr) #define unlikely(expr) (expr)