small optimization for {f()}
This commit is contained in:
@@ -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
|
** Lua Parser
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@@ -483,6 +483,7 @@ static void lastlistfield (FuncState *fs, struct ConsControl *cc) {
|
|||||||
if (cc->v.k == VCALL) {
|
if (cc->v.k == VCALL) {
|
||||||
luaK_setcallreturns(fs, &cc->v, LUA_MULTRET);
|
luaK_setcallreturns(fs, &cc->v, LUA_MULTRET);
|
||||||
luaK_codeABx(fs, OP_SETLISTO, cc->t->info, cc->na-1);
|
luaK_codeABx(fs, OP_SETLISTO, cc->t->info, cc->na-1);
|
||||||
|
cc->na--; /* do not count last expression (unknown number of elements) */
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (cc->v.k != VVOID)
|
if (cc->v.k != VVOID)
|
||||||
|
|||||||
6
ltable.c
6
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)
|
** Lua tables (hash)
|
||||||
** See Copyright Notice in lua.h
|
** 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 i;
|
||||||
int oldasize = t->sizearray;
|
int oldasize = t->sizearray;
|
||||||
int oldhsize = t->lsizenode;
|
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) {
|
static void rehash (lua_State *L, Table *t) {
|
||||||
int nasize, nhsize;
|
int nasize, nhsize;
|
||||||
numuse(t, &nasize, &nhsize); /* compute new sizes for array and hash parts */
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
3
ltable.h
3
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)
|
** Lua tables (hash)
|
||||||
** See Copyright Notice in lua.h
|
** 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);
|
const TValue *luaH_get (Table *t, const TValue *key);
|
||||||
TValue *luaH_set (lua_State *L, 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);
|
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);
|
void luaH_free (lua_State *L, Table *t);
|
||||||
int luaH_next (lua_State *L, Table *t, StkId key);
|
int luaH_next (lua_State *L, Table *t, StkId key);
|
||||||
|
|
||||||
|
|||||||
7
lvm.c
7
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
|
** Lua virtual machine
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@@ -701,12 +701,11 @@ StkId luaV_execute (lua_State *L, int nexeccalls) {
|
|||||||
}
|
}
|
||||||
case OP_SETLIST:
|
case OP_SETLIST:
|
||||||
case OP_SETLISTO: {
|
case OP_SETLISTO: {
|
||||||
int bc;
|
int bc = GETARG_Bx(i);
|
||||||
int n;
|
int n;
|
||||||
Table *h;
|
Table *h;
|
||||||
runtime_check(L, ttistable(ra));
|
runtime_check(L, ttistable(ra));
|
||||||
h = hvalue(ra);
|
h = hvalue(ra);
|
||||||
bc = GETARG_Bx(i);
|
|
||||||
if (GET_OPCODE(i) == OP_SETLIST)
|
if (GET_OPCODE(i) == OP_SETLIST)
|
||||||
n = (bc&(LFIELDS_PER_FLUSH-1)) + 1;
|
n = (bc&(LFIELDS_PER_FLUSH-1)) + 1;
|
||||||
else {
|
else {
|
||||||
@@ -714,6 +713,8 @@ StkId luaV_execute (lua_State *L, int nexeccalls) {
|
|||||||
L->top = L->ci->top;
|
L->top = L->ci->top;
|
||||||
}
|
}
|
||||||
bc &= ~(LFIELDS_PER_FLUSH-1); /* bc = bc - bc%FPF */
|
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--) {
|
for (; n > 0; n--) {
|
||||||
TValue *val = ra+n;
|
TValue *val = ra+n;
|
||||||
setobj2t(L, luaH_setnum(L, h, bc+n), val);
|
setobj2t(L, luaH_setnum(L, h, bc+n), val);
|
||||||
|
|||||||
Reference in New Issue
Block a user