Optimization for vararg tables
A vararg table can be virtual. If the vararg table is used only as a base in indexing expressions, the code does not need to create an actual table for it. Instead, it compiles the indexing expressions into direct accesses to the internal vararg data.
This commit is contained in:
22
ltm.c
22
ltm.c
@@ -277,6 +277,28 @@ void luaT_adjustvarargs (lua_State *L, CallInfo *ci, const Proto *p) {
|
||||
}
|
||||
|
||||
|
||||
void luaT_getvararg (CallInfo *ci, StkId ra, TValue *rc) {
|
||||
int nextra = ci->u.l.nextraargs;
|
||||
lua_Integer n;
|
||||
if (tointegerns(rc, &n)) { /* integral value? */
|
||||
if (l_castS2U(n) - 1 < cast_uint(nextra)) {
|
||||
StkId slot = ci->func.p - nextra + cast_int(n) - 1;
|
||||
setobjs2s(((lua_State*)NULL), ra, slot);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (ttisshrstring(rc)) { /* short-string value? */
|
||||
size_t len;
|
||||
const char *s = getlstr(tsvalue(rc), len);
|
||||
if (len == 1 && s[0] == 'n') { /* key is "n"? */
|
||||
setivalue(s2v(ra), nextra);
|
||||
return;
|
||||
}
|
||||
}
|
||||
setnilvalue(s2v(ra)); /* else produce nil */
|
||||
}
|
||||
|
||||
|
||||
void luaT_getvarargs (lua_State *L, CallInfo *ci, StkId where, int wanted) {
|
||||
int i;
|
||||
int nextra = ci->u.l.nextraargs;
|
||||
|
||||
Reference in New Issue
Block a user