'luaH_get' functions return tag of the result · lua/lua@0593256 · GitHub
Skip to content

Commit 0593256

Browse files
committed
'luaH_get' functions return tag of the result
Undoing previous commit. Returning TValue increases code size without any visible gains. Returning the tag is a little simpler than returning a special code (HOK/HNOTFOUND) and the tag is useful by itself in some cases.
1 parent ce6f550 commit 0593256

10 files changed

Lines changed: 138 additions & 132 deletions

File tree

‎lapi.c‎

Lines changed: 35 additions & 34 deletions

‎lcode.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -541,11 +541,12 @@ static void freeexps (FuncState *fs, expdesc *e1, expdesc *e2) {
541541
** a function can make some indices wrong.
542542
*/
543543
static int addk (FuncState *fs, TValue *key, TValue *v) {
544+
TValue val;
544545
lua_State *L = fs->ls->L;
545546
Proto *f = fs->f;
546-
TValue val = luaH_get(fs->ls->h, key); /* query scanner table */
547+
int tag = luaH_get(fs->ls->h, key, &val); /* query scanner table */
547548
int k, oldsize;
548-
if (ttisintegerV(val)) { /* is there an index there? */
549+
if (tag == LUA_VNUMINT) { /* is there an index there? */
549550
k = cast_int(ivalue(&val));
550551
/* correct value? (warning: must distinguish floats from integers!) */
551552
if (k < fs->nk && ttypetag(&f->k[k]) == ttypetag(v) &&

‎ldump.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,9 @@ static void dumpString (DumpState *D, TString *ts) {
132132
if (ts == NULL)
133133
dumpSize(D, 0);
134134
else {
135-
TValue idx = luaH_getstr(D->h, ts);
136-
if (!isemptyV(idx)) { /* string already saved? */
135+
TValue idx;
136+
int tag = luaH_getstr(D->h, ts, &idx);
137+
if (!tagisempty(tag)) { /* string already saved? */
137138
dumpSize(D, 1); /* reuse a saved string */
138139
dumpSize(D, cast_sizet(ivalue(&idx))); /* index of saved string */
139140
}

‎lobject.h‎

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -75,26 +75,21 @@ typedef struct TValue {
7575

7676
/* raw type tag of a TValue */
7777
#define rawtt(o) ((o)->tt_)
78-
#define rawttV(o) ((o).tt_)
7978

8079
/* tag with no variants (bits 0-3) */
8180
#define novariant(t) ((t) & 0x0F)
8281

8382
/* type tag of a TValue (bits 0-3 for tags + variant bits 4-5) */
8483
#define withvariant(t) ((t) & 0x3F)
8584
#define ttypetag(o) withvariant(rawtt(o))
86-
#define ttypetagV(o) withvariant(rawttV(o))
8785

8886
/* type of a TValue */
8987
#define ttype(o) (novariant(rawtt(o)))
90-
#define ttypeV(o) (novariant(rawttV(o)))
9188

9289

9390
/* Macros to test type */
9491
#define checktag(o,t) (rawtt(o) == (t))
95-
#define checktagV(o,t) (rawttV(o) == (t))
9692
#define checktype(o,t) (ttype(o) == (t))
97-
#define checktypeV(o,t) (ttypeV(o) == (t))
9893

9994

10095
/* Macros for internal tests */
@@ -117,7 +112,6 @@ typedef struct TValue {
117112

118113
/* set a value's tag */
119114
#define settt_(o,t) ((o)->tt_=(t))
120-
#define setttV_(o,t) ((o).tt_=(t))
121115

122116

123117
/* main macro to copy values (from 'obj2' to 'obj1') */
@@ -126,11 +120,6 @@ typedef struct TValue {
126120
io1->value_ = io2->value_; settt_(io1, io2->tt_); \
127121
checkliveness(L,io1); lua_assert(!isnonstrictnil(io1)); }
128122

129-
#define setobjV(L,obj1,obj2) \
130-
{ TValue *io1=(obj1); const TValue io2=(obj2); \
131-
io1->value_ = io2.value_; settt_(io1, io2.tt_); \
132-
checkliveness(L,io1); lua_assert(!isnonstrictnil(io1)); }
133-
134123
/*
135124
** Different types of assignments, according to source and destination.
136125
** (They are mostly equal now, but may be different in the future.)
@@ -199,16 +188,19 @@ typedef union {
199188
/* Value returned for a key not found in a table (absent key) */
200189
#define LUA_VABSTKEY makevariant(LUA_TNIL, 2)
201190

202-
/* Special "value" to signal that a fast get is accessing a non-table */
203-
#define LUA_VNOTABLE makevariant(LUA_TNIL, 3)
204-
205-
#define setnotableV(obj) setttV_(obj, LUA_VNOTABLE)
191+
/* Special variant to signal that a fast get is accessing a non-table */
192+
#define LUA_VNOTABLE makevariant(LUA_TNIL, 3)
206193

207194

208195
/* macro to test for (any kind of) nil */
209196
#define ttisnil(v) checktype((v), LUA_TNIL)
210-
#define ttisnilV(v) checktypeV((v), LUA_TNIL)
211197

198+
/*
199+
** Macro to test the result of a table access. Formally, it should
200+
** distinguish between LUA_VEMPTY/LUA_VABSTKEY/LUA_VNOTABLE and
201+
** other tags. As currently nil is equivalent to LUA_VEMPTY, it is
202+
** simpler to just test whether the value is nil.
203+
*/
212204
#define tagisempty(tag) (novariant(tag) == LUA_TNIL)
213205

214206

@@ -234,7 +226,6 @@ typedef union {
234226
** be accepted as empty.)
235227
*/
236228
#define isempty(v) ttisnil(v)
237-
#define isemptyV(v) checktypeV((v), LUA_TNIL)
238229

239230

240231
/* macro defining a value corresponding to an absent key */
@@ -346,7 +337,6 @@ typedef struct GCObject {
346337
#define ttisnumber(o) checktype((o), LUA_TNUMBER)
347338
#define ttisfloat(o) checktag((o), LUA_VNUMFLT)
348339
#define ttisinteger(o) checktag((o), LUA_VNUMINT)
349-
#define ttisintegerV(o) checktagV((o), LUA_VNUMINT)
350340

351341
#define nvalue(o) check_exp(ttisnumber(o), \
352342
(ttisinteger(o) ? cast_num(ivalue(o)) : fltvalue(o)))

‎ltable.c‎

Lines changed: 30 additions & 18 deletions

0 commit comments

Comments
 (0)