aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2004-03-26 11:02:41 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2004-03-26 11:02:41 -0300
commit4c5d7b2dddeb853b61489d02b738572eb29cb323 (patch)
tree98fd0c7ad24d788bb60c8aee568fad856f630b89
parentd7cb62286642b0f5c16057373ff129109e1a3e8a (diff)
downloadlua-4c5d7b2dddeb853b61489d02b738572eb29cb323.tar.gz
lua-4c5d7b2dddeb853b61489d02b738572eb29cb323.tar.bz2
lua-4c5d7b2dddeb853b61489d02b738572eb29cb323.zip
small optimization for {f()}
-rw-r--r--lparser.c3
-rw-r--r--ltable.c6
-rw-r--r--ltable.h3
-rw-r--r--lvm.c7
4 files changed, 11 insertions, 8 deletions
diff --git a/lparser.c b/lparser.c
index ec5ae272..b8e1b2a7 100644
--- a/lparser.c
+++ b/lparser.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lparser.c,v 2.1 2003/12/10 12:13:36 roberto Exp roberto $ 2** $Id: lparser.c,v 2.2 2004/03/12 19:53:56 roberto Exp roberto $
3** Lua Parser 3** Lua Parser
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -483,6 +483,7 @@ static void lastlistfield (FuncState *fs, struct ConsControl *cc) {
483 if (cc->v.k == VCALL) { 483 if (cc->v.k == VCALL) {
484 luaK_setcallreturns(fs, &cc->v, LUA_MULTRET); 484 luaK_setcallreturns(fs, &cc->v, LUA_MULTRET);
485 luaK_codeABx(fs, OP_SETLISTO, cc->t->info, cc->na-1); 485 luaK_codeABx(fs, OP_SETLISTO, cc->t->info, cc->na-1);
486 cc->na--; /* do not count last expression (unknown number of elements) */
486 } 487 }
487 else { 488 else {
488 if (cc->v.k != VVOID) 489 if (cc->v.k != VVOID)
diff --git a/ltable.c b/ltable.c
index 797690b4..fff4716d 100644
--- a/ltable.c
+++ b/ltable.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltable.c,v 1.138 2003/12/09 16:56:11 roberto Exp roberto $ 2** $Id: ltable.c,v 2.1 2003/12/10 12:13:36 roberto Exp roberto $
3** Lua tables (hash) 3** Lua tables (hash)
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -270,7 +270,7 @@ static void setnodevector (lua_State *L, Table *t, int lsize) {
270} 270}
271 271
272 272
273static void resize (lua_State *L, Table *t, int nasize, int nhsize) { 273void luaH_resize (lua_State *L, Table *t, int nasize, int nhsize) {
274 int i; 274 int i;
275 int oldasize = t->sizearray; 275 int oldasize = t->sizearray;
276 int oldhsize = t->lsizenode; 276 int oldhsize = t->lsizenode;
@@ -315,7 +315,7 @@ static void resize (lua_State *L, Table *t, int nasize, int nhsize) {
315static void rehash (lua_State *L, Table *t) { 315static void rehash (lua_State *L, Table *t) {
316 int nasize, nhsize; 316 int nasize, nhsize;
317 numuse(t, &nasize, &nhsize); /* compute new sizes for array and hash parts */ 317 numuse(t, &nasize, &nhsize); /* compute new sizes for array and hash parts */
318 resize(L, t, nasize, luaO_log2(nhsize)+1); 318 luaH_resize(L, t, nasize, luaO_log2(nhsize)+1);
319} 319}
320 320
321 321
diff --git a/ltable.h b/ltable.h
index e953bb70..902beec4 100644
--- a/ltable.h
+++ b/ltable.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltable.h,v 1.45 2003/08/26 12:04:13 roberto Exp roberto $ 2** $Id: ltable.h,v 2.1 2003/12/10 12:13:36 roberto Exp roberto $
3** Lua tables (hash) 3** Lua tables (hash)
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -22,6 +22,7 @@ TValue *luaH_setstr (lua_State *L, Table *t, TString *key);
22const TValue *luaH_get (Table *t, const TValue *key); 22const TValue *luaH_get (Table *t, const TValue *key);
23TValue *luaH_set (lua_State *L, Table *t, const TValue *key); 23TValue *luaH_set (lua_State *L, Table *t, const TValue *key);
24Table *luaH_new (lua_State *L, int narray, int lnhash); 24Table *luaH_new (lua_State *L, int narray, int lnhash);
25void luaH_resize (lua_State *L, Table *t, int nasize, int nhsize);
25void luaH_free (lua_State *L, Table *t); 26void luaH_free (lua_State *L, Table *t);
26int luaH_next (lua_State *L, Table *t, StkId key); 27int luaH_next (lua_State *L, Table *t, StkId key);
27 28
diff --git a/lvm.c b/lvm.c
index a953bfc9..779245f2 100644
--- a/lvm.c
+++ b/lvm.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lvm.c,v 2.1 2003/12/10 12:13:36 roberto Exp roberto $ 2** $Id: lvm.c,v 2.2 2004/03/16 12:31:40 roberto Exp roberto $
3** Lua virtual machine 3** Lua virtual machine
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -701,12 +701,11 @@ StkId luaV_execute (lua_State *L, int nexeccalls) {
701 } 701 }
702 case OP_SETLIST: 702 case OP_SETLIST:
703 case OP_SETLISTO: { 703 case OP_SETLISTO: {
704 int bc; 704 int bc = GETARG_Bx(i);
705 int n; 705 int n;
706 Table *h; 706 Table *h;
707 runtime_check(L, ttistable(ra)); 707 runtime_check(L, ttistable(ra));
708 h = hvalue(ra); 708 h = hvalue(ra);
709 bc = GETARG_Bx(i);
710 if (GET_OPCODE(i) == OP_SETLIST) 709 if (GET_OPCODE(i) == OP_SETLIST)
711 n = (bc&(LFIELDS_PER_FLUSH-1)) + 1; 710 n = (bc&(LFIELDS_PER_FLUSH-1)) + 1;
712 else { 711 else {
@@ -714,6 +713,8 @@ StkId luaV_execute (lua_State *L, int nexeccalls) {
714 L->top = L->ci->top; 713 L->top = L->ci->top;
715 } 714 }
716 bc &= ~(LFIELDS_PER_FLUSH-1); /* bc = bc - bc%FPF */ 715 bc &= ~(LFIELDS_PER_FLUSH-1); /* bc = bc - bc%FPF */
716 if (bc+n > h->sizearray) /* needs more space? */
717 luaH_resize(L, h, bc+n, h->lsizenode); /* pre-alloc it at once */
717 for (; n > 0; n--) { 718 for (; n > 0; n--) {
718 TValue *val = ra+n; 719 TValue *val = ra+n;
719 setobj2t(L, luaH_setnum(L, h, bc+n), val); 720 setobj2t(L, luaH_setnum(L, h, bc+n), val);