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.
This commit is contained in:
Roberto Ierusalimschy
2017-06-12 11:21:44 -03:00
parent d13a3fb070
commit 73ec04fcf3
5 changed files with 49 additions and 66 deletions

View File

@@ -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)