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 | |
parent | 18afb90349fc1b698d179e29fdc014589c2e1145 (diff) | |
download | lua-42754c0f15ded97342d3aa67f719e1962fab702a.tar.gz lua-42754c0f15ded97342d3aa67f719e1962fab702a.tar.bz2 lua-42754c0f15ded97342d3aa67f719e1962fab702a.zip |
small optimizations
-rw-r--r-- | lapi.c | 4 | ||||
-rw-r--r-- | ldo.c | 10 | ||||
-rw-r--r-- | ldo.h | 1 | ||||
-rw-r--r-- | lvm.c | 32 |
4 files changed, 18 insertions, 29 deletions
@@ -104,7 +104,9 @@ LUA_API void lua_settop (lua_State *L, int index) { | |||
104 | lua_lock(L); | 104 | lua_lock(L); |
105 | if (index >= 0) { | 105 | if (index >= 0) { |
106 | api_check(L, index <= L->stack_last - L->ci->base); | 106 | api_check(L, index <= L->stack_last - L->ci->base); |
107 | luaD_adjusttop(L, L->ci->base+index); | 107 | while (L->top < L->ci->base + index) |
108 | setnilvalue(L->top++); | ||
109 | L->top = L->ci->base + index; | ||
108 | } | 110 | } |
109 | else { | 111 | else { |
110 | api_check(L, -(index+1) <= (L->top - L->ci->base)); | 112 | api_check(L, -(index+1) <= (L->top - L->ci->base)); |
@@ -69,16 +69,6 @@ void luaD_stackerror (lua_State *L) { | |||
69 | 69 | ||
70 | 70 | ||
71 | /* | 71 | /* |
72 | ** adjust top to new value; assume that new top is valid | ||
73 | */ | ||
74 | void luaD_adjusttop (lua_State *L, StkId newtop) { | ||
75 | while (L->top < newtop) | ||
76 | setnilvalue(L->top++); | ||
77 | L->top = newtop; /* `newtop' could be lower than `top' */ | ||
78 | } | ||
79 | |||
80 | |||
81 | /* | ||
82 | ** Open a hole inside the stack at `pos' | 72 | ** Open a hole inside the stack at `pos' |
83 | */ | 73 | */ |
84 | static void luaD_openstack (lua_State *L, StkId pos) { | 74 | static void luaD_openstack (lua_State *L, StkId pos) { |
@@ -23,7 +23,6 @@ | |||
23 | 23 | ||
24 | 24 | ||
25 | void luaD_init (lua_State *L, int stacksize); | 25 | void luaD_init (lua_State *L, int stacksize); |
26 | void luaD_adjusttop (lua_State *L, StkId newtop); | ||
27 | void luaD_lineHook (lua_State *L, int line, lua_Hook linehook); | 26 | void luaD_lineHook (lua_State *L, int line, lua_Hook linehook); |
28 | void luaD_callHook (lua_State *L, lua_Hook callhook, const char *event); | 27 | void luaD_callHook (lua_State *L, lua_Hook callhook, const char *event); |
29 | StkId luaD_precall (lua_State *L, StkId func); | 28 | StkId luaD_precall (lua_State *L, StkId func); |
@@ -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; |