From 73ec04fcf3e3f7017786fbaf0a83291b22bec5c4 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Mon, 12 Jun 2017 11:21:44 -0300 Subject: no more 'DEADKEY'. Table traversals do not need to consider dead keys; if the key is dead, it cannot be given to 'next'. Instead, we now use a 'table' tag without the collectable bit, which makes it a unique tag good enough to reserve space. --- lobject.h | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'lobject.h') diff --git a/lobject.h b/lobject.h index 97afa143..e245f306 100644 --- a/lobject.h +++ b/lobject.h @@ -1,5 +1,5 @@ /* -** $Id: lobject.h,v 2.121 2017/06/01 20:24:05 roberto Exp roberto $ +** $Id: lobject.h,v 2.122 2017/06/09 16:48:44 roberto Exp roberto $ ** Type definitions for Lua objects ** See Copyright Notice in lua.h */ @@ -21,10 +21,9 @@ */ #define LUA_TUPVAL LUA_NUMTAGS /* upvalues */ #define LUA_TPROTO (LUA_NUMTAGS+1) /* function prototypes */ -#define LUA_TDEADKEY (LUA_NUMTAGS+2) /* removed keys in tables */ /* -** number of all possible tags (including LUA_TNONE but excluding DEADKEY) +** number of all possible tags (including LUA_TNONE) */ #define LUA_TOTALTAGS (LUA_TPROTO + 2) @@ -559,14 +558,7 @@ typedef struct Table { #define keyisshrstr(node) (keytt(node) == ctb(LUA_TSHRSTR)) #define keystrval(node) (gco2ts(keyval(node).gc)) -#define keyisdead(node) (keytt(node) == LUA_TDEADKEY) - #define setnilkey(node) (keytt(node) = LUA_TNIL) -#define setdeadkey(node) (keytt(node) = LUA_TDEADKEY) - -/* a dead value may get the 'gc' field, but cannot access its contents */ -#define deadkey(n) \ - check_exp(keytt(n) == LUA_TDEADKEY, cast(void *, keyval(n).gc)) #define keyiscollectable(n) (keytt(n) & BIT_ISCOLLECTABLE) @@ -574,6 +566,16 @@ typedef struct Table { #define gckeyN(n) (keyiscollectable(n) ? gckey(n) : NULL) +/* +** Use a "nil table" to mark dead keys in a table. Those keys serve +** only to keep space for removed entries, which may still be part of +** chains. Note that the 'keytt' does not have the BIT_ISCOLLECTABLE +** set, so these values are considered not collectable and are different +** from any valid value. +*/ +#define setdeadkey(n) (keytt(n) = LUA_TTABLE, gckey(n) = NULL) + + /* ** 'module' operation for hashing (size is always a power of 2) -- cgit v1.2.3-55-g6feb