From 25c54fe60e22d05cdfaa48c64372d354efa59547 Mon Sep 17 00:00:00 2001 From: Roberto I Date: Wed, 24 Sep 2025 18:33:08 -0300 Subject: 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. --- lparser.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'lparser.c') diff --git a/lparser.c b/lparser.c index 8b909f3d..408b8e21 100644 --- a/lparser.c +++ b/lparser.c @@ -279,7 +279,9 @@ static void init_var (FuncState *fs, expdesc *e, int vidx) { /* -** Raises an error if variable described by 'e' is read only +** Raises an error if variable described by 'e' is read only; moreover, +** if 'e' is t[exp] where t is the vararg parameter, change it to index +** a real table. (Virtual vararg tables cannot be changed.) */ static void check_readonly (LexState *ls, expdesc *e) { FuncState *fs = ls->fs; @@ -301,6 +303,10 @@ static void check_readonly (LexState *ls, expdesc *e) { varname = up->name; break; } + case VVARGIND: { + fs->f->flag |= PF_VATAB; /* function will need a vararg table */ + e->k = VINDEXED; + } /* FALLTHROUGH */ case VINDEXUP: case VINDEXSTR: case VINDEXED: { /* global variable */ if (e->u.ind.ro) /* read-only? */ varname = tsvalue(&fs->f->k[e->u.ind.keystr]); @@ -1073,7 +1079,7 @@ static void parlist (LexState *ls) { case TK_DOTS: { varargk |= PF_ISVARARG; luaX_next(ls); - if (testnext(ls, '=')) { + if (testnext(ls, '|')) { new_varkind(ls, str_checkname(ls), RDKVAVAR); varargk |= PF_VAVAR; } -- cgit v1.2.3-55-g6feb