Skip to content
This repository was archived by the owner on Sep 20, 2023. It is now read-only.

Commit 934e77a

Browse files
committed
Details
- Better comments about short strings in opcodes. - luaH_newkey made static.
1 parent 6443185 commit 934e77a

File tree

5 files changed

+14
-14
lines changed

5 files changed

+14
-14
lines changed

lcode.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -1215,7 +1215,7 @@ static void codenot (FuncState *fs, expdesc *e) {
12151215

12161216

12171217
/*
1218-
** Check whether expression 'e' is a small literal string
1218+
** Check whether expression 'e' is a short literal string
12191219
*/
12201220
static int isKstr (FuncState *fs, expdesc *e) {
12211221
return (e->k == VK && !hasjumps(e) && e->u.info <= MAXARG_B &&
@@ -1283,15 +1283,16 @@ void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k) {
12831283
if (t->k == VUPVAL && !isKstr(fs, k)) /* upvalue indexed by non 'Kstr'? */
12841284
luaK_exp2anyreg(fs, t); /* put it in a register */
12851285
if (t->k == VUPVAL) {
1286+
lua_assert(isKstr(fs, k));
12861287
t->u.ind.t = t->u.info; /* upvalue index */
1287-
t->u.ind.idx = k->u.info; /* literal string */
1288+
t->u.ind.idx = k->u.info; /* literal short string */
12881289
t->k = VINDEXUP;
12891290
}
12901291
else {
12911292
/* register index of the table */
12921293
t->u.ind.t = (t->k == VLOCAL) ? t->u.var.ridx: t->u.info;
12931294
if (isKstr(fs, k)) {
1294-
t->u.ind.idx = k->u.info; /* literal string */
1295+
t->u.ind.idx = k->u.info; /* literal short string */
12951296
t->k = VINDEXSTR;
12961297
}
12971298
else if (isCint(k)) {

lopcodes.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -210,15 +210,15 @@ OP_LOADNIL,/* A B R[A], R[A+1], ..., R[A+B] := nil */
210210
OP_GETUPVAL,/* A B R[A] := UpValue[B] */
211211
OP_SETUPVAL,/* A B UpValue[B] := R[A] */
212212

213-
OP_GETTABUP,/* A B C R[A] := UpValue[B][K[C]:string] */
213+
OP_GETTABUP,/* A B C R[A] := UpValue[B][K[C]:shortstring] */
214214
OP_GETTABLE,/* A B C R[A] := R[B][R[C]] */
215215
OP_GETI,/* A B C R[A] := R[B][C] */
216-
OP_GETFIELD,/* A B C R[A] := R[B][K[C]:string] */
216+
OP_GETFIELD,/* A B C R[A] := R[B][K[C]:shortstring] */
217217

218-
OP_SETTABUP,/* A B C UpValue[A][K[B]:string] := RK(C) */
218+
OP_SETTABUP,/* A B C UpValue[A][K[B]:shortstring] := RK(C) */
219219
OP_SETTABLE,/* A B C R[A][R[B]] := RK(C) */
220220
OP_SETI,/* A B C R[A][B] := RK(C) */
221-
OP_SETFIELD,/* A B C R[A][K[B]:string] := RK(C) */
221+
OP_SETFIELD,/* A B C R[A][K[B]:shortstring] := RK(C) */
222222

223223
OP_NEWTABLE,/* A B C k R[A] := {} */
224224

ltable.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,8 @@ static Node *getfreepos (Table *t) {
662662
** put new key in its main position; otherwise (colliding node is in its main
663663
** position), new key goes to an empty position.
664664
*/
665-
void luaH_newkey (lua_State *L, Table *t, const TValue *key, TValue *value) {
665+
static void luaH_newkey (lua_State *L, Table *t, const TValue *key,
666+
TValue *value) {
666667
Node *mp;
667668
TValue aux;
668669
if (l_unlikely(ttisnil(key)))

ltable.h

-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ LUAI_FUNC void luaH_setint (lua_State *L, Table *t, lua_Integer key,
4141
LUAI_FUNC const TValue *luaH_getshortstr (Table *t, TString *key);
4242
LUAI_FUNC const TValue *luaH_getstr (Table *t, TString *key);
4343
LUAI_FUNC const TValue *luaH_get (Table *t, const TValue *key);
44-
LUAI_FUNC void luaH_newkey (lua_State *L, Table *t, const TValue *key,
45-
TValue *value);
4644
LUAI_FUNC void luaH_set (lua_State *L, Table *t, const TValue *key,
4745
TValue *value);
4846
LUAI_FUNC void luaH_finishset (lua_State *L, Table *t, const TValue *key,

lvm.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -1253,7 +1253,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
12531253
const TValue *slot;
12541254
TValue *upval = cl->upvals[GETARG_B(i)]->v.p;
12551255
TValue *rc = KC(i);
1256-
TString *key = tsvalue(rc); /* key must be a string */
1256+
TString *key = tsvalue(rc); /* key must be a short string */
12571257
if (luaV_fastget(L, upval, key, slot, luaH_getshortstr)) {
12581258
setobj2s(L, ra, slot);
12591259
}
@@ -1296,7 +1296,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
12961296
const TValue *slot;
12971297
TValue *rb = vRB(i);
12981298
TValue *rc = KC(i);
1299-
TString *key = tsvalue(rc); /* key must be a string */
1299+
TString *key = tsvalue(rc); /* key must be a short string */
13001300
if (luaV_fastget(L, rb, key, slot, luaH_getshortstr)) {
13011301
setobj2s(L, ra, slot);
13021302
}
@@ -1309,7 +1309,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
13091309
TValue *upval = cl->upvals[GETARG_A(i)]->v.p;
13101310
TValue *rb = KB(i);
13111311
TValue *rc = RKC(i);
1312-
TString *key = tsvalue(rb); /* key must be a string */
1312+
TString *key = tsvalue(rb); /* key must be a short string */
13131313
if (luaV_fastget(L, upval, key, slot, luaH_getshortstr)) {
13141314
luaV_finishfastset(L, upval, slot, rc);
13151315
}
@@ -1352,7 +1352,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
13521352
const TValue *slot;
13531353
TValue *rb = KB(i);
13541354
TValue *rc = RKC(i);
1355-
TString *key = tsvalue(rb); /* key must be a string */
1355+
TString *key = tsvalue(rb); /* key must be a short string */
13561356
if (luaV_fastget(L, s2v(ra), key, slot, luaH_getshortstr)) {
13571357
luaV_finishfastset(L, s2v(ra), slot, rc);
13581358
}

0 commit comments

Comments
 (0)