From: Ivan Maidanski Date: Thu, 7 Dec 2017 08:54:15 +0000 (+0300) Subject: Use __builtin_expect in SIZET_SAT_ADD macro X-Git-Tag: v8.0.0~459 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=cae1bcac8b7e91808706a29b023ccd7cb963e5d1;p=platform%2Fupstream%2Flibgc.git Use __builtin_expect in SIZET_SAT_ADD macro * include/private/gc_priv.h (EXPECT): Move the definition to be before SIZET_SAT_ADD. * include/private/gc_priv.h (SIZET_SAT_ADD): Use EXPECT(). --- diff --git a/include/private/gc_priv.h b/include/private/gc_priv.h index 108bebc..42128ff 100644 --- a/include/private/gc_priv.h +++ b/include/private/gc_priv.h @@ -106,10 +106,17 @@ typedef char * ptr_t; /* A generic pointer to which we can add */ # define GC_SIZE_MAX (~(size_t)0) #endif +#if GC_GNUC_PREREQ(3, 0) && !defined(LINT2) +# define EXPECT(expr, outcome) __builtin_expect(expr,outcome) + /* Equivalent to (expr), but predict that usually (expr)==outcome. */ +#else +# define EXPECT(expr, outcome) (expr) +#endif /* __GNUC__ */ + /* Saturated addition of size_t values. Used to avoid value wrap */ /* around on overflow. The arguments should have no side effects. */ #define SIZET_SAT_ADD(a, b) \ - ((a) < GC_SIZE_MAX - (b) ? (a) + (b) : GC_SIZE_MAX) + (EXPECT((a) < GC_SIZE_MAX - (b), TRUE) ? (a) + (b) : GC_SIZE_MAX) #ifndef GCCONFIG_H # include "gcconfig.h" @@ -192,13 +199,6 @@ typedef char * ptr_t; /* A generic pointer to which we can add */ # endif #endif /* !GC_ATTR_UNUSED */ -#if GC_GNUC_PREREQ(3, 0) && !defined(LINT2) -# define EXPECT(expr, outcome) __builtin_expect(expr,outcome) - /* Equivalent to (expr), but predict that usually (expr)==outcome. */ -#else -# define EXPECT(expr, outcome) (expr) -#endif /* __GNUC__ */ - #ifdef HAVE_CONFIG_H /* The "inline" keyword is determined by Autoconf AC_C_INLINE. */ # define GC_INLINE static inline