aboutsummaryrefslogtreecommitdiff
path: root/ltm.c
diff options
context:
space:
mode:
authorRoberto I <roberto@inf.puc-rio.br>2025-09-24 18:33:08 -0300
committerRoberto I <roberto@inf.puc-rio.br>2025-09-24 18:33:08 -0300
commit25c54fe60e22d05cdfaa48c64372d354efa59547 (patch)
tree3ccaeded5e4363db358f73b7c8fc6b9f414a2f2a /ltm.c
parent0cc3c9447cca9abae9738ee77c24d88801c3916c (diff)
downloadlua-25c54fe60e22d05cdfaa48c64372d354efa59547.tar.gz
lua-25c54fe60e22d05cdfaa48c64372d354efa59547.tar.bz2
lua-25c54fe60e22d05cdfaa48c64372d354efa59547.zip
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.
Diffstat (limited to 'ltm.c')
-rw-r--r--ltm.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/ltm.c b/ltm.c
index cc812e62..92a03e71 100644
--- a/ltm.c
+++ b/ltm.c
@@ -277,6 +277,28 @@ void luaT_adjustvarargs (lua_State *L, CallInfo *ci, const Proto *p) {
277} 277}
278 278
279 279
280void luaT_getvararg (CallInfo *ci, StkId ra, TValue *rc) {
281 int nextra = ci->u.l.nextraargs;
282 lua_Integer n;
283 if (tointegerns(rc, &n)) { /* integral value? */
284 if (l_castS2U(n) - 1 < cast_uint(nextra)) {
285 StkId slot = ci->func.p - nextra + cast_int(n) - 1;
286 setobjs2s(((lua_State*)NULL), ra, slot);
287 return;
288 }
289 }
290 else if (ttisshrstring(rc)) { /* short-string value? */
291 size_t len;
292 const char *s = getlstr(tsvalue(rc), len);
293 if (len == 1 && s[0] == 'n') { /* key is "n"? */
294 setivalue(s2v(ra), nextra);
295 return;
296 }
297 }
298 setnilvalue(s2v(ra)); /* else produce nil */
299}
300
301
280void luaT_getvarargs (lua_State *L, CallInfo *ci, StkId where, int wanted) { 302void luaT_getvarargs (lua_State *L, CallInfo *ci, StkId where, int wanted) {
281 int i; 303 int i;
282 int nextra = ci->u.l.nextraargs; 304 int nextra = ci->u.l.nextraargs;