Use __builtin_expect in SIZET_SAT_ADD macro
authorIvan Maidanski <ivmai@mail.ru>
Thu, 7 Dec 2017 08:54:15 +0000 (11:54 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Thu, 7 Dec 2017 08:54:15 +0000 (11:54 +0300)
* 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().

include/private/gc_priv.h

index 108bebc..42128ff 100644 (file)
@@ -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