aboutsummaryrefslogtreecommitdiff
path: root/lobject.h
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2017-06-12 11:21:44 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2017-06-12 11:21:44 -0300
commit73ec04fcf3e3f7017786fbaf0a83291b22bec5c4 (patch)
treeb2870a1e832fa3e013b67209592db32b611f8e5f /lobject.h
parentd13a3fb070fd0ec9ec3b85f88e0fcd914aa666d3 (diff)
downloadlua-73ec04fcf3e3f7017786fbaf0a83291b22bec5c4.tar.gz
lua-73ec04fcf3e3f7017786fbaf0a83291b22bec5c4.tar.bz2
lua-73ec04fcf3e3f7017786fbaf0a83291b22bec5c4.zip
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.
Diffstat (limited to 'lobject.h')
-rw-r--r--lobject.h22
1 files changed, 12 insertions, 10 deletions
diff --git a/lobject.h b/lobject.h
index 97afa143..e245f306 100644
--- a/lobject.h
+++ b/lobject.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lobject.h,v 2.121 2017/06/01 20:24:05 roberto Exp roberto $ 2** $Id: lobject.h,v 2.122 2017/06/09 16:48:44 roberto Exp roberto $
3** Type definitions for Lua objects 3** Type definitions for Lua objects
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -21,10 +21,9 @@
21*/ 21*/
22#define LUA_TUPVAL LUA_NUMTAGS /* upvalues */ 22#define LUA_TUPVAL LUA_NUMTAGS /* upvalues */
23#define LUA_TPROTO (LUA_NUMTAGS+1) /* function prototypes */ 23#define LUA_TPROTO (LUA_NUMTAGS+1) /* function prototypes */
24#define LUA_TDEADKEY (LUA_NUMTAGS+2) /* removed keys in tables */
25 24
26/* 25/*
27** number of all possible tags (including LUA_TNONE but excluding DEADKEY) 26** number of all possible tags (including LUA_TNONE)
28*/ 27*/
29#define LUA_TOTALTAGS (LUA_TPROTO + 2) 28#define LUA_TOTALTAGS (LUA_TPROTO + 2)
30 29
@@ -559,14 +558,7 @@ typedef struct Table {
559#define keyisshrstr(node) (keytt(node) == ctb(LUA_TSHRSTR)) 558#define keyisshrstr(node) (keytt(node) == ctb(LUA_TSHRSTR))
560#define keystrval(node) (gco2ts(keyval(node).gc)) 559#define keystrval(node) (gco2ts(keyval(node).gc))
561 560
562#define keyisdead(node) (keytt(node) == LUA_TDEADKEY)
563
564#define setnilkey(node) (keytt(node) = LUA_TNIL) 561#define setnilkey(node) (keytt(node) = LUA_TNIL)
565#define setdeadkey(node) (keytt(node) = LUA_TDEADKEY)
566
567/* a dead value may get the 'gc' field, but cannot access its contents */
568#define deadkey(n) \
569 check_exp(keytt(n) == LUA_TDEADKEY, cast(void *, keyval(n).gc))
570 562
571#define keyiscollectable(n) (keytt(n) & BIT_ISCOLLECTABLE) 563#define keyiscollectable(n) (keytt(n) & BIT_ISCOLLECTABLE)
572 564
@@ -574,6 +566,16 @@ typedef struct Table {
574#define gckeyN(n) (keyiscollectable(n) ? gckey(n) : NULL) 566#define gckeyN(n) (keyiscollectable(n) ? gckey(n) : NULL)
575 567
576 568
569/*
570** Use a "nil table" to mark dead keys in a table. Those keys serve
571** only to keep space for removed entries, which may still be part of
572** chains. Note that the 'keytt' does not have the BIT_ISCOLLECTABLE
573** set, so these values are considered not collectable and are different
574** from any valid value.
575*/
576#define setdeadkey(n) (keytt(n) = LUA_TTABLE, gckey(n) = NULL)
577
578
577 579
578/* 580/*
579** 'module' operation for hashing (size is always a power of 2) 581** 'module' operation for hashing (size is always a power of 2)