Some cleaning in the new table API
This commit is contained in:
112
lvm.c
112
lvm.c
@@ -281,15 +281,13 @@ static int floatforloop (StkId ra) {
|
||||
|
||||
/*
|
||||
** Finish the table access 'val = t[key]'.
|
||||
** if 'slot' is NULL, 't' is not a table; otherwise, 'slot' points to
|
||||
** t[k] entry (which must be empty).
|
||||
*/
|
||||
void luaV_finishget1 (lua_State *L, const TValue *t, TValue *key, StkId val,
|
||||
int aux) {
|
||||
void luaV_finishget (lua_State *L, const TValue *t, TValue *key, StkId val,
|
||||
int hres) {
|
||||
int loop; /* counter to avoid infinite loops */
|
||||
const TValue *tm; /* metamethod */
|
||||
for (loop = 0; loop < MAXTAGLOOP; loop++) {
|
||||
if (aux == HNOTATABLE) { /* 't' is not a table? */
|
||||
if (hres == HNOTATABLE) { /* 't' is not a table? */
|
||||
lua_assert(!ttistable(t));
|
||||
tm = luaT_gettmbyobj(L, t, TM_INDEX);
|
||||
if (l_unlikely(notm(tm)))
|
||||
@@ -309,8 +307,8 @@ void luaV_finishget1 (lua_State *L, const TValue *t, TValue *key, StkId val,
|
||||
return;
|
||||
}
|
||||
t = tm; /* else try to access 'tm[key]' */
|
||||
luaV_fastget1(t, key, s2v(val), luaH_get1, aux);
|
||||
if (aux == HOK)
|
||||
luaV_fastget(t, key, s2v(val), luaH_get, hres);
|
||||
if (hres == HOK)
|
||||
return; /* done */
|
||||
/* else repeat (tail call 'luaV_finishget') */
|
||||
}
|
||||
@@ -320,21 +318,17 @@ void luaV_finishget1 (lua_State *L, const TValue *t, TValue *key, StkId val,
|
||||
|
||||
/*
|
||||
** Finish a table assignment 't[key] = val'.
|
||||
** If 'slot' is NULL, 't' is not a table. Otherwise, 'slot' points
|
||||
** to the entry 't[key]', or to a value with an absent key if there
|
||||
** is no such entry. (The value at 'slot' must be empty, otherwise
|
||||
** 'luaV_fastget' would have done the job.)
|
||||
*/
|
||||
void luaV_finishset1 (lua_State *L, const TValue *t, TValue *key,
|
||||
TValue *val, int aux) {
|
||||
void luaV_finishset (lua_State *L, const TValue *t, TValue *key,
|
||||
TValue *val, int hres) {
|
||||
int loop; /* counter to avoid infinite loops */
|
||||
for (loop = 0; loop < MAXTAGLOOP; loop++) {
|
||||
const TValue *tm; /* '__newindex' metamethod */
|
||||
if (aux != HNOTATABLE) { /* is 't' a table? */
|
||||
if (hres != HNOTATABLE) { /* is 't' a table? */
|
||||
Table *h = hvalue(t); /* save 't' table */
|
||||
tm = fasttm(L, h->metatable, TM_NEWINDEX); /* get metamethod */
|
||||
if (tm == NULL) { /* no metamethod? */
|
||||
luaH_finishset1(L, h, key, val, aux); /* set new value */
|
||||
luaH_finishset(L, h, key, val, hres); /* set new value */
|
||||
invalidateTMcache(h);
|
||||
luaC_barrierback(L, obj2gco(h), val);
|
||||
return;
|
||||
@@ -352,8 +346,8 @@ void luaV_finishset1 (lua_State *L, const TValue *t, TValue *key,
|
||||
return;
|
||||
}
|
||||
t = tm; /* else repeat assignment over 'tm' */
|
||||
luaV_fastset1(t, key, val, aux, luaH_set1);
|
||||
if (aux == HOK)
|
||||
luaV_fastset(t, key, val, hres, luaH_pset);
|
||||
if (hres == HOK)
|
||||
return; /* done */
|
||||
/* else 'return luaV_finishset(L, t, key, val, slot)' (loop) */
|
||||
}
|
||||
@@ -1249,36 +1243,36 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
|
||||
TValue *upval = cl->upvals[GETARG_B(i)]->v.p;
|
||||
TValue *rc = KC(i);
|
||||
TString *key = tsvalue(rc); /* key must be a string */
|
||||
int aux;
|
||||
luaV_fastget1(upval, key, s2v(ra), luaH_getshortstr1, aux);
|
||||
if (aux != HOK)
|
||||
Protect(luaV_finishget1(L, upval, rc, ra, aux));
|
||||
int hres;
|
||||
luaV_fastget(upval, key, s2v(ra), luaH_getshortstr, hres);
|
||||
if (hres != HOK)
|
||||
Protect(luaV_finishget(L, upval, rc, ra, hres));
|
||||
vmbreak;
|
||||
}
|
||||
vmcase(OP_GETTABLE) {
|
||||
StkId ra = RA(i);
|
||||
TValue *rb = vRB(i);
|
||||
TValue *rc = vRC(i);
|
||||
int aux;
|
||||
int hres;
|
||||
if (ttisinteger(rc)) { /* fast track for integers? */
|
||||
luaV_fastgeti1(rb, ivalue(rc), s2v(ra), aux);
|
||||
luaV_fastgeti(rb, ivalue(rc), s2v(ra), hres);
|
||||
}
|
||||
else
|
||||
luaV_fastget1(rb, rc, s2v(ra), luaH_get1, aux);
|
||||
if (aux != HOK) /* fast track for integers? */
|
||||
Protect(luaV_finishget1(L, rb, rc, ra, aux));
|
||||
luaV_fastget(rb, rc, s2v(ra), luaH_get, hres);
|
||||
if (hres != HOK) /* fast track for integers? */
|
||||
Protect(luaV_finishget(L, rb, rc, ra, hres));
|
||||
vmbreak;
|
||||
}
|
||||
vmcase(OP_GETI) {
|
||||
StkId ra = RA(i);
|
||||
TValue *rb = vRB(i);
|
||||
int c = GETARG_C(i);
|
||||
int aux;
|
||||
luaV_fastgeti1(rb, c, s2v(ra), aux);
|
||||
if (aux != HOK) {
|
||||
int hres;
|
||||
luaV_fastgeti(rb, c, s2v(ra), hres);
|
||||
if (hres != HOK) {
|
||||
TValue key;
|
||||
setivalue(&key, c);
|
||||
Protect(luaV_finishget1(L, rb, &key, ra, aux));
|
||||
Protect(luaV_finishget(L, rb, &key, ra, hres));
|
||||
}
|
||||
vmbreak;
|
||||
}
|
||||
@@ -1287,68 +1281,68 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
|
||||
TValue *rb = vRB(i);
|
||||
TValue *rc = KC(i);
|
||||
TString *key = tsvalue(rc); /* key must be a string */
|
||||
int aux;
|
||||
luaV_fastget1(rb, key, s2v(ra), luaH_getshortstr1, aux);
|
||||
if (aux != HOK)
|
||||
Protect(luaV_finishget1(L, rb, rc, ra, aux));
|
||||
int hres;
|
||||
luaV_fastget(rb, key, s2v(ra), luaH_getshortstr, hres);
|
||||
if (hres != HOK)
|
||||
Protect(luaV_finishget(L, rb, rc, ra, hres));
|
||||
vmbreak;
|
||||
}
|
||||
vmcase(OP_SETTABUP) {
|
||||
int aux;
|
||||
int hres;
|
||||
TValue *upval = cl->upvals[GETARG_A(i)]->v.p;
|
||||
TValue *rb = KB(i);
|
||||
TValue *rc = RKC(i);
|
||||
TString *key = tsvalue(rb); /* key must be a string */
|
||||
luaV_fastset1(upval, key, rc, aux, luaH_setshortstr1);
|
||||
if (aux == HOK)
|
||||
luaV_finishfastset1(L, upval, rc);
|
||||
luaV_fastset(upval, key, rc, hres, luaH_psetshortstr);
|
||||
if (hres == HOK)
|
||||
luaV_finishfastset(L, upval, rc);
|
||||
else
|
||||
Protect(luaV_finishset1(L, upval, rb, rc, aux));
|
||||
Protect(luaV_finishset(L, upval, rb, rc, hres));
|
||||
vmbreak;
|
||||
}
|
||||
vmcase(OP_SETTABLE) {
|
||||
StkId ra = RA(i);
|
||||
int aux;
|
||||
int hres;
|
||||
TValue *rb = vRB(i); /* key (table is in 'ra') */
|
||||
TValue *rc = RKC(i); /* value */
|
||||
if (ttisinteger(rb)) { /* fast track for integers? */
|
||||
luaV_fastseti1(s2v(ra), ivalue(rb), rc, aux);
|
||||
luaV_fastseti(s2v(ra), ivalue(rb), rc, hres);
|
||||
}
|
||||
else {
|
||||
luaV_fastset1(s2v(ra), rb, rc, aux, luaH_set1);
|
||||
luaV_fastset(s2v(ra), rb, rc, hres, luaH_pset);
|
||||
}
|
||||
if (aux == HOK)
|
||||
luaV_finishfastset1(L, s2v(ra), rc);
|
||||
if (hres == HOK)
|
||||
luaV_finishfastset(L, s2v(ra), rc);
|
||||
else
|
||||
Protect(luaV_finishset1(L, s2v(ra), rb, rc, aux));
|
||||
Protect(luaV_finishset(L, s2v(ra), rb, rc, hres));
|
||||
vmbreak;
|
||||
}
|
||||
vmcase(OP_SETI) {
|
||||
StkId ra = RA(i);
|
||||
int aux;
|
||||
int hres;
|
||||
int b = GETARG_B(i);
|
||||
TValue *rc = RKC(i);
|
||||
luaV_fastseti1(s2v(ra), b, rc, aux);
|
||||
if (aux == HOK)
|
||||
luaV_finishfastset1(L, s2v(ra), rc);
|
||||
luaV_fastseti(s2v(ra), b, rc, hres);
|
||||
if (hres == HOK)
|
||||
luaV_finishfastset(L, s2v(ra), rc);
|
||||
else {
|
||||
TValue key;
|
||||
setivalue(&key, b);
|
||||
Protect(luaV_finishset1(L, s2v(ra), &key, rc, aux));
|
||||
Protect(luaV_finishset(L, s2v(ra), &key, rc, hres));
|
||||
}
|
||||
vmbreak;
|
||||
}
|
||||
vmcase(OP_SETFIELD) {
|
||||
StkId ra = RA(i);
|
||||
int aux;
|
||||
int hres;
|
||||
TValue *rb = KB(i);
|
||||
TValue *rc = RKC(i);
|
||||
TString *key = tsvalue(rb); /* key must be a string */
|
||||
luaV_fastset1(s2v(ra), key, rc, aux, luaH_setshortstr1);
|
||||
if (aux == HOK)
|
||||
luaV_finishfastset1(L, s2v(ra), rc);
|
||||
luaV_fastset(s2v(ra), key, rc, hres, luaH_psetshortstr);
|
||||
if (hres == HOK)
|
||||
luaV_finishfastset(L, s2v(ra), rc);
|
||||
else
|
||||
Protect(luaV_finishset1(L, s2v(ra), rb, rc, aux));
|
||||
Protect(luaV_finishset(L, s2v(ra), rb, rc, hres));
|
||||
vmbreak;
|
||||
}
|
||||
vmcase(OP_NEWTABLE) {
|
||||
@@ -1372,14 +1366,14 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
|
||||
}
|
||||
vmcase(OP_SELF) {
|
||||
StkId ra = RA(i);
|
||||
int aux;
|
||||
int hres;
|
||||
TValue *rb = vRB(i);
|
||||
TValue *rc = RKC(i);
|
||||
TString *key = tsvalue(rc); /* key must be a string */
|
||||
setobj2s(L, ra + 1, rb);
|
||||
luaV_fastget1(rb, key, s2v(ra), luaH_getstr1, aux);
|
||||
if (aux != HOK)
|
||||
Protect(luaV_finishget1(L, rb, rc, ra, aux));
|
||||
luaV_fastget(rb, key, s2v(ra), luaH_getstr, hres);
|
||||
if (hres != HOK)
|
||||
Protect(luaV_finishget(L, rb, rc, ra, hres));
|
||||
vmbreak;
|
||||
}
|
||||
vmcase(OP_ADDI) {
|
||||
|
||||
Reference in New Issue
Block a user