commit 4c5d7b2dddeb853b61489d02b738572eb29cb323
parent d7cb62286642b0f5c16057373ff129109e1a3e8a
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date: Fri, 26 Mar 2004 11:02:19 -0300
small optimization for {f()}
Diffstat:
4 files changed, 11 insertions(+), 8 deletions(-)
diff --git a/lparser.c b/lparser.c
@@ -1,5 +1,5 @@
/*
-** $Id: lparser.c,v 2.1 2003/12/10 12:13:36 roberto Exp roberto $
+** $Id: lparser.c,v 2.2 2004/03/12 19:53:56 roberto Exp roberto $
** Lua Parser
** See Copyright Notice in lua.h
*/
@@ -483,6 +483,7 @@ static void lastlistfield (FuncState *fs, struct ConsControl *cc) {
if (cc->v.k == VCALL) {
luaK_setcallreturns(fs, &cc->v, LUA_MULTRET);
luaK_codeABx(fs, OP_SETLISTO, cc->t->info, cc->na-1);
+ cc->na--; /* do not count last expression (unknown number of elements) */
}
else {
if (cc->v.k != VVOID)
diff --git a/ltable.c b/ltable.c
@@ -1,5 +1,5 @@
/*
-** $Id: ltable.c,v 1.138 2003/12/09 16:56:11 roberto Exp roberto $
+** $Id: ltable.c,v 2.1 2003/12/10 12:13:36 roberto Exp roberto $
** Lua tables (hash)
** See Copyright Notice in lua.h
*/
@@ -270,7 +270,7 @@ static void setnodevector (lua_State *L, Table *t, int lsize) {
}
-static void resize (lua_State *L, Table *t, int nasize, int nhsize) {
+void luaH_resize (lua_State *L, Table *t, int nasize, int nhsize) {
int i;
int oldasize = t->sizearray;
int oldhsize = t->lsizenode;
@@ -315,7 +315,7 @@ static void resize (lua_State *L, Table *t, int nasize, int nhsize) {
static void rehash (lua_State *L, Table *t) {
int nasize, nhsize;
numuse(t, &nasize, &nhsize); /* compute new sizes for array and hash parts */
- resize(L, t, nasize, luaO_log2(nhsize)+1);
+ luaH_resize(L, t, nasize, luaO_log2(nhsize)+1);
}
diff --git a/ltable.h b/ltable.h
@@ -1,5 +1,5 @@
/*
-** $Id: ltable.h,v 1.45 2003/08/26 12:04:13 roberto Exp roberto $
+** $Id: ltable.h,v 2.1 2003/12/10 12:13:36 roberto Exp roberto $
** Lua tables (hash)
** See Copyright Notice in lua.h
*/
@@ -22,6 +22,7 @@ TValue *luaH_setstr (lua_State *L, Table *t, TString *key);
const TValue *luaH_get (Table *t, const TValue *key);
TValue *luaH_set (lua_State *L, Table *t, const TValue *key);
Table *luaH_new (lua_State *L, int narray, int lnhash);
+void luaH_resize (lua_State *L, Table *t, int nasize, int nhsize);
void luaH_free (lua_State *L, Table *t);
int luaH_next (lua_State *L, Table *t, StkId key);
diff --git a/lvm.c b/lvm.c
@@ -1,5 +1,5 @@
/*
-** $Id: lvm.c,v 2.1 2003/12/10 12:13:36 roberto Exp roberto $
+** $Id: lvm.c,v 2.2 2004/03/16 12:31:40 roberto Exp roberto $
** Lua virtual machine
** See Copyright Notice in lua.h
*/
@@ -701,12 +701,11 @@ StkId luaV_execute (lua_State *L, int nexeccalls) {
}
case OP_SETLIST:
case OP_SETLISTO: {
- int bc;
+ int bc = GETARG_Bx(i);
int n;
Table *h;
runtime_check(L, ttistable(ra));
h = hvalue(ra);
- bc = GETARG_Bx(i);
if (GET_OPCODE(i) == OP_SETLIST)
n = (bc&(LFIELDS_PER_FLUSH-1)) + 1;
else {
@@ -714,6 +713,8 @@ StkId luaV_execute (lua_State *L, int nexeccalls) {
L->top = L->ci->top;
}
bc &= ~(LFIELDS_PER_FLUSH-1); /* bc = bc - bc%FPF */
+ if (bc+n > h->sizearray) /* needs more space? */
+ luaH_resize(L, h, bc+n, h->lsizenode); /* pre-alloc it at once */
for (; n > 0; n--) {
TValue *val = ra+n;
setobj2t(L, luaH_setnum(L, h, bc+n), val);