lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


The use of defined(__GNUC__) alone for the conditional for
__builtin_expect is ugly; there may be non-gcc compilers that support it
too.

You could do something like:

#ifdef __has_builtin
#define luai_has_builtin(x) __has_builtin(x)
#else
#define luai_has_builtin(x) 0
#endif

#if luai_has_builtin(__builtin_expect) || (__GNUC__ >= 3)
#define luai_likely(x)   (__builtin_expect(((x) != 0), 1))
#define luai_unlikely(x) (__builtin_expect(((x) != 0), 0))
#else
#define luai_likely(x)   ((x) != 0)
#define luai_unlikely(x) ((x) != 0)
#endif

-- 
Andrew.