diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2001-12-20 19:26:52 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2001-12-20 19:26:52 -0200 |
commit | 42754c0f15ded97342d3aa67f719e1962fab702a (patch) | |
tree | 5d90865c6b16474307aeba155550184ad12df5a6 /lvm.c | |
parent | 18afb90349fc1b698d179e29fdc014589c2e1145 (diff) | |
download | lua-42754c0f15ded97342d3aa67f719e1962fab702a.tar.gz lua-42754c0f15ded97342d3aa67f719e1962fab702a.tar.bz2 lua-42754c0f15ded97342d3aa67f719e1962fab702a.zip |
small optimizations
Diffstat (limited to 'lvm.c')
-rw-r--r-- | lvm.c | 32 |
1 files changed, 15 insertions, 17 deletions
@@ -256,33 +256,29 @@ void luaV_strconc (lua_State *L, int total, StkId top) { | |||
256 | } | 256 | } |
257 | 257 | ||
258 | 258 | ||
259 | static void luaV_pack (lua_State *L, StkId firstelem) { | 259 | static void adjust_varargs (lua_State *L, StkId base, int nfixargs) { |
260 | int i; | 260 | int i; |
261 | Table *htab = luaH_new(L, 0, 0); | 261 | Table *htab; |
262 | TObject n, nname; | 262 | TObject n, nname; |
263 | for (i=0; firstelem+i<L->top; i++) | 263 | StkId firstvar = base + nfixargs; /* position of first vararg */ |
264 | luaH_setnum(L, htab, i+1, firstelem+i); | 264 | if (L->top < firstvar) { |
265 | luaD_checkstack(L, firstvar - L->top); | ||
266 | while (L->top < firstvar) | ||
267 | setnilvalue(L->top++); | ||
268 | } | ||
269 | htab = luaH_new(L, 0, 0); | ||
270 | for (i=0; firstvar+i<L->top; i++) | ||
271 | luaH_setnum(L, htab, i+1, firstvar+i); | ||
265 | /* store counter in field `n' */ | 272 | /* store counter in field `n' */ |
266 | setnvalue(&n, i); | 273 | setnvalue(&n, i); |
267 | setsvalue(&nname, luaS_newliteral(L, "n")); | 274 | setsvalue(&nname, luaS_newliteral(L, "n")); |
268 | luaH_set(L, htab, &nname, &n); | 275 | luaH_set(L, htab, &nname, &n); |
269 | L->top = firstelem; /* remove elements from the stack */ | 276 | L->top = firstvar; /* remove elements from the stack */ |
270 | sethvalue(L->top, htab); | 277 | sethvalue(L->top, htab); |
271 | incr_top; | 278 | incr_top; |
272 | } | 279 | } |
273 | 280 | ||
274 | 281 | ||
275 | static void adjust_varargs (lua_State *L, StkId base, int nfixargs) { | ||
276 | int nvararg = (L->top-base) - nfixargs; | ||
277 | StkId firstvar = base + nfixargs; /* position of first vararg */ | ||
278 | if (nvararg < 0) { | ||
279 | luaD_checkstack(L, -nvararg); | ||
280 | luaD_adjusttop(L, firstvar); | ||
281 | } | ||
282 | luaV_pack(L, firstvar); | ||
283 | } | ||
284 | |||
285 | |||
286 | static void powOp (lua_State *L, StkId ra, StkId rb, StkId rc) { | 282 | static void powOp (lua_State *L, StkId ra, StkId rb, StkId rc) { |
287 | const TObject *b = rb; | 283 | const TObject *b = rb; |
288 | const TObject *c = rc; | 284 | const TObject *c = rc; |
@@ -352,7 +348,9 @@ StkId luaV_execute (lua_State *L, const LClosure *cl, StkId base) { | |||
352 | adjust_varargs(L, base, cl->p->numparams); | 348 | adjust_varargs(L, base, cl->p->numparams); |
353 | if (base > L->stack_last - cl->p->maxstacksize) | 349 | if (base > L->stack_last - cl->p->maxstacksize) |
354 | luaD_stackerror(L); | 350 | luaD_stackerror(L); |
355 | luaD_adjusttop(L, base + cl->p->maxstacksize); | 351 | while (L->top < base + cl->p->maxstacksize) |
352 | setnilvalue(L->top++); | ||
353 | L->top = base + cl->p->maxstacksize; | ||
356 | L->ci->pc = &pc; | 354 | L->ci->pc = &pc; |
357 | linehook = L->ci->linehook = L->linehook; | 355 | linehook = L->ci->linehook = L->linehook; |
358 | pc = cl->p->code; | 356 | pc = cl->p->code; |