From 5ff408d2189c6c24fdf8908db4a31432bbdd6f15 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Mon, 6 Jan 2020 11:38:31 -0300 Subject: Changed internal representation of booleans Instead of an explicit value (field 'b'), true and false use different tag variants. This avoids reading an extra field and results in more direct code. (Most code that uses booleans needs to distinguish between true and false anyway.) --- lobject.h | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'lobject.h') diff --git a/lobject.h b/lobject.h index 7d30b46f..a529ceba 100644 --- a/lobject.h +++ b/lobject.h @@ -44,7 +44,6 @@ typedef union Value { struct GCObject *gc; /* collectable objects */ void *p; /* light userdata */ - int b; /* booleans */ lua_CFunction f; /* light C functions */ lua_Integer i; /* integer numbers */ lua_Number n; /* float numbers */ @@ -210,16 +209,20 @@ typedef StackValue *StkId; ** =================================================================== */ -#define ttisboolean(o) checktag((o), LUA_TBOOLEAN) -#define bvalue(o) check_exp(ttisboolean(o), val_(o).b) +#define LUA_TFALSE (LUA_TBOOLEAN | (1 << 4)) +#define LUA_TTRUE (LUA_TBOOLEAN | (2 << 4)) -#define bvalueraw(v) ((v).b) +#define ttisboolean(o) checktype((o), LUA_TBOOLEAN) +#define ttisfalse(o) checktag((o), LUA_TFALSE) +#define ttistrue(o) checktag((o), LUA_TTRUE) -#define l_isfalse(o) (ttisboolean(o) ? bvalue(o) == 0 : ttisnil(o)) -#define setbvalue(obj,x) \ - { TValue *io=(obj); val_(io).b=(x); settt_(io, LUA_TBOOLEAN); } +#define l_isfalse(o) (ttisfalse(o) || ttisnil(o)) + + +#define setbfvalue(obj) settt_(obj, LUA_TFALSE) +#define setbtvalue(obj) settt_(obj, LUA_TTRUE) /* }================================================================== */ -- cgit v1.2.3-55-g6feb