Broadening the use of branch hints

More uses of macros 'likely'/'unlikely' (renamed to
'l_likely'/'l_unlikely'), both in range (extended to the
libraries) and in scope (extended to hooks, stack growth).
This commit is contained in:
Roberto Ierusalimschy
2021-02-24 11:14:44 -03:00
parent c03c527fd2
commit 59c88f846d
24 changed files with 162 additions and 141 deletions

View File

@@ -660,6 +660,26 @@
#define lua_getlocaledecpoint() (localeconv()->decimal_point[0])
#endif
/*
** macros to improve jump prediction, used mostly for error handling
** and debug facilities.
*/
#if (defined(LUA_CORE) || defined(LUA_LIB)) && !defined(l_likely)
#include <stdio.h>
#if defined(__GNUC__)
#define l_likely(x) (__builtin_expect(((x) != 0), 1))
#define l_unlikely(x) (__builtin_expect(((x) != 0), 0))
#else
#define l_likely(x) (x)
#define l_unlikely(x) (x)
#endif
#endif
/* }================================================================== */