mirror of
https://github.com/lua/lua
synced 2024-11-29 08:03:13 +03:00
Uses of "likely" in macros active to all users
The use of 'l_likely' in auxlib macros 'luaL_argcheck' and 'luaL_argexpected' should not be restricted to Lua's own code. For that, 'l_likely' was renamed to 'luai_likely' to be exported to external code.
This commit is contained in:
parent
511d53a826
commit
a7b8b27dd3
@ -12,6 +12,7 @@
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "luaconf.h"
|
||||
#include "lua.h"
|
||||
|
||||
|
||||
@ -122,10 +123,6 @@ LUALIB_API void (luaL_requiref) (lua_State *L, const char *modname,
|
||||
** ===============================================================
|
||||
*/
|
||||
|
||||
#if !defined(l_likely)
|
||||
#define l_likely(x) x
|
||||
#endif
|
||||
|
||||
|
||||
#define luaL_newlibtable(L,l) \
|
||||
lua_createtable(L, 0, sizeof(l)/sizeof((l)[0]) - 1)
|
||||
@ -134,10 +131,10 @@ LUALIB_API void (luaL_requiref) (lua_State *L, const char *modname,
|
||||
(luaL_checkversion(L), luaL_newlibtable(L,l), luaL_setfuncs(L,l,0))
|
||||
|
||||
#define luaL_argcheck(L, cond,arg,extramsg) \
|
||||
((void)(l_likely(cond) || luaL_argerror(L, (arg), (extramsg))))
|
||||
((void)(luai_likely(cond) || luaL_argerror(L, (arg), (extramsg))))
|
||||
|
||||
#define luaL_argexpected(L,cond,arg,tname) \
|
||||
((void)(l_likely(cond) || luaL_typeerror(L, (arg), (tname))))
|
||||
((void)(luai_likely(cond) || luaL_typeerror(L, (arg), (tname))))
|
||||
|
||||
#define luaL_checkstring(L,n) (luaL_checklstring(L, (n), NULL))
|
||||
#define luaL_optstring(L,n,d) (luaL_optlstring(L, (n), (d), NULL))
|
||||
|
18
luaconf.h
18
luaconf.h
@ -665,20 +665,26 @@
|
||||
** macros to improve jump prediction, used mostly for error handling
|
||||
** and debug facilities.
|
||||
*/
|
||||
#if (defined(LUA_CORE) || defined(LUA_LIB)) && !defined(l_likely)
|
||||
#if !defined(luai_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))
|
||||
#define luai_likely(x) (__builtin_expect(((x) != 0), 1))
|
||||
#define luai_unlikely(x) (__builtin_expect(((x) != 0), 0))
|
||||
#else
|
||||
#define l_likely(x) (x)
|
||||
#define l_unlikely(x) (x)
|
||||
#define luai_likely(x) (x)
|
||||
#define luai_unlikely(x) (x)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(LUA_CORE) || defined(LUA_LIB)
|
||||
/* shorter names for Lua's own use */
|
||||
#define l_likely(x) luai_likely(x)
|
||||
#define l_unlikely(x) luai_unlikely(x)
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/* }================================================================== */
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user