diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2012-08-16 14:34:28 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2012-08-16 14:34:28 -0300 |
| commit | a3e1c40d6d6fb81db9d8b58aee69466f715aab5c (patch) | |
| tree | ea11a028d8d92772ad97879c7bc5bbe50318bbea | |
| parent | c1a2a646c81000b03a243cbdeba9c4bd6dd7b474 (diff) | |
| download | lua-a3e1c40d6d6fb81db9d8b58aee69466f715aab5c.tar.gz lua-a3e1c40d6d6fb81db9d8b58aee69466f715aab5c.tar.bz2 lua-a3e1c40d6d6fb81db9d8b58aee69466f715aab5c.zip | |
remove of unecessary luaD_checkstack. (In some cases, C should
ensure stack space; in others, Lua can use the extra slots for
temporary values.)
| -rw-r--r-- | lcode.c | 9 | ||||
| -rw-r--r-- | ldebug.c | 10 | ||||
| -rw-r--r-- | lobject.c | 16 | ||||
| -rw-r--r-- | ltests.c | 4 | ||||
| -rw-r--r-- | lvm.c | 3 |
5 files changed, 19 insertions, 23 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lcode.c,v 2.60 2011/08/30 16:26:41 roberto Exp roberto $ | 2 | ** $Id: lcode.c,v 2.61 2012/08/14 18:12:34 roberto Exp roberto $ |
| 3 | ** Code generator for Lua | 3 | ** Code generator for Lua |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -330,10 +330,9 @@ int luaK_numberK (FuncState *fs, lua_Number r) { | |||
| 330 | setnvalue(&o, r); | 330 | setnvalue(&o, r); |
| 331 | if (r == 0 || luai_numisnan(NULL, r)) { /* handle -0 and NaN */ | 331 | if (r == 0 || luai_numisnan(NULL, r)) { /* handle -0 and NaN */ |
| 332 | /* use raw representation as key to avoid numeric problems */ | 332 | /* use raw representation as key to avoid numeric problems */ |
| 333 | setsvalue(L, L->top, luaS_newlstr(L, (char *)&r, sizeof(r))); | 333 | setsvalue(L, L->top++, luaS_newlstr(L, (char *)&r, sizeof(r))); |
| 334 | incr_top(L); | 334 | n = addk(fs, L->top - 1, &o); |
| 335 | n = addk(fs, L->top - 1, &o); | 335 | L->top--; |
| 336 | L->top--; | ||
| 337 | } | 336 | } |
| 338 | else | 337 | else |
| 339 | n = addk(fs, &o, &o); /* regular case */ | 338 | n = addk(fs, &o, &o); /* regular case */ |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ldebug.c,v 2.88 2011/11/30 12:43:51 roberto Exp roberto $ | 2 | ** $Id: ldebug.c,v 2.89 2012/01/20 22:05:50 roberto Exp roberto $ |
| 3 | ** Debug Interface | 3 | ** Debug Interface |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -196,7 +196,7 @@ static void funcinfo (lua_Debug *ar, Closure *cl) { | |||
| 196 | static void collectvalidlines (lua_State *L, Closure *f) { | 196 | static void collectvalidlines (lua_State *L, Closure *f) { |
| 197 | if (noLuaClosure(f)) { | 197 | if (noLuaClosure(f)) { |
| 198 | setnilvalue(L->top); | 198 | setnilvalue(L->top); |
| 199 | incr_top(L); | 199 | api_incr_top(L); |
| 200 | } | 200 | } |
| 201 | else { | 201 | else { |
| 202 | int i; | 202 | int i; |
| @@ -204,7 +204,7 @@ static void collectvalidlines (lua_State *L, Closure *f) { | |||
| 204 | int *lineinfo = f->l.p->lineinfo; | 204 | int *lineinfo = f->l.p->lineinfo; |
| 205 | Table *t = luaH_new(L); /* new table to store active lines */ | 205 | Table *t = luaH_new(L); /* new table to store active lines */ |
| 206 | sethvalue(L, L->top, t); /* push it on stack */ | 206 | sethvalue(L, L->top, t); /* push it on stack */ |
| 207 | incr_top(L); | 207 | api_incr_top(L); |
| 208 | setbvalue(&v, 1); /* boolean 'true' to be the value of all indices */ | 208 | setbvalue(&v, 1); /* boolean 'true' to be the value of all indices */ |
| 209 | for (i = 0; i < f->l.p->sizelineinfo; i++) /* for all lines with code */ | 209 | for (i = 0; i < f->l.p->sizelineinfo; i++) /* for all lines with code */ |
| 210 | luaH_setint(L, t, lineinfo[i], &v); /* table[line] = true */ | 210 | luaH_setint(L, t, lineinfo[i], &v); /* table[line] = true */ |
| @@ -285,7 +285,7 @@ LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) { | |||
| 285 | status = auxgetinfo(L, what, ar, cl, ci); | 285 | status = auxgetinfo(L, what, ar, cl, ci); |
| 286 | if (strchr(what, 'f')) { | 286 | if (strchr(what, 'f')) { |
| 287 | setobjs2s(L, L->top, func); | 287 | setobjs2s(L, L->top, func); |
| 288 | incr_top(L); | 288 | api_incr_top(L); |
| 289 | } | 289 | } |
| 290 | if (strchr(what, 'L')) | 290 | if (strchr(what, 'L')) |
| 291 | collectvalidlines(L, cl); | 291 | collectvalidlines(L, cl); |
| @@ -563,7 +563,7 @@ l_noret luaG_errormsg (lua_State *L) { | |||
| 563 | if (!ttisfunction(errfunc)) luaD_throw(L, LUA_ERRERR); | 563 | if (!ttisfunction(errfunc)) luaD_throw(L, LUA_ERRERR); |
| 564 | setobjs2s(L, L->top, L->top - 1); /* move argument */ | 564 | setobjs2s(L, L->top, L->top - 1); /* move argument */ |
| 565 | setobjs2s(L, L->top - 1, errfunc); /* push function */ | 565 | setobjs2s(L, L->top - 1, errfunc); /* push function */ |
| 566 | incr_top(L); | 566 | L->top++; |
| 567 | luaD_call(L, L->top - 2, 1, 0); /* call it */ | 567 | luaD_call(L, L->top - 2, 1, 0); /* call it */ |
| 568 | } | 568 | } |
| 569 | luaD_throw(L, LUA_ERRRUN); | 569 | luaD_throw(L, LUA_ERRRUN); |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lobject.c,v 2.54 2011/11/30 12:44:26 roberto Exp roberto $ | 2 | ** $Id: lobject.c,v 2.55 2011/11/30 19:30:16 roberto Exp roberto $ |
| 3 | ** Some generic functions over Lua objects | 3 | ** Some generic functions over Lua objects |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -171,8 +171,7 @@ int luaO_str2d (const char *s, size_t len, lua_Number *result) { | |||
| 171 | 171 | ||
| 172 | 172 | ||
| 173 | static void pushstr (lua_State *L, const char *str, size_t l) { | 173 | static void pushstr (lua_State *L, const char *str, size_t l) { |
| 174 | setsvalue2s(L, L->top, luaS_newlstr(L, str, l)); | 174 | setsvalue2s(L, L->top++, luaS_newlstr(L, str, l)); |
| 175 | incr_top(L); | ||
| 176 | } | 175 | } |
| 177 | 176 | ||
| 178 | 177 | ||
| @@ -182,8 +181,8 @@ const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) { | |||
| 182 | for (;;) { | 181 | for (;;) { |
| 183 | const char *e = strchr(fmt, '%'); | 182 | const char *e = strchr(fmt, '%'); |
| 184 | if (e == NULL) break; | 183 | if (e == NULL) break; |
| 185 | setsvalue2s(L, L->top, luaS_newlstr(L, fmt, e-fmt)); | 184 | luaD_checkstack(L, 2); /* fmt + item */ |
| 186 | incr_top(L); | 185 | pushstr(L, fmt, e - fmt); |
| 187 | switch (*(e+1)) { | 186 | switch (*(e+1)) { |
| 188 | case 's': { | 187 | case 's': { |
| 189 | const char *s = va_arg(argp, char *); | 188 | const char *s = va_arg(argp, char *); |
| @@ -198,13 +197,11 @@ const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) { | |||
| 198 | break; | 197 | break; |
| 199 | } | 198 | } |
| 200 | case 'd': { | 199 | case 'd': { |
| 201 | setnvalue(L->top, cast_num(va_arg(argp, int))); | 200 | setnvalue(L->top++, cast_num(va_arg(argp, int))); |
| 202 | incr_top(L); | ||
| 203 | break; | 201 | break; |
| 204 | } | 202 | } |
| 205 | case 'f': { | 203 | case 'f': { |
| 206 | setnvalue(L->top, cast_num(va_arg(argp, l_uacNumber))); | 204 | setnvalue(L->top++, cast_num(va_arg(argp, l_uacNumber))); |
| 207 | incr_top(L); | ||
| 208 | break; | 205 | break; |
| 209 | } | 206 | } |
| 210 | case 'p': { | 207 | case 'p': { |
| @@ -226,6 +223,7 @@ const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) { | |||
| 226 | n += 2; | 223 | n += 2; |
| 227 | fmt = e+2; | 224 | fmt = e+2; |
| 228 | } | 225 | } |
| 226 | luaD_checkstack(L, 1); | ||
| 229 | pushstr(L, fmt, strlen(fmt)); | 227 | pushstr(L, fmt, strlen(fmt)); |
| 230 | if (n > 0) luaV_concat(L, n + 1); | 228 | if (n > 0) luaV_concat(L, n + 1); |
| 231 | return svalue(L->top - 1); | 229 | return svalue(L->top - 1); |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ltests.c,v 2.131 2012/07/02 15:38:36 roberto Exp roberto $ | 2 | ** $Id: ltests.c,v 2.132 2012/07/04 15:52:38 roberto Exp roberto $ |
| 3 | ** Internal Module for Debugging of the Lua Implementation | 3 | ** Internal Module for Debugging of the Lua Implementation |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -753,7 +753,7 @@ static int string_query (lua_State *L) { | |||
| 753 | int n = 0; | 753 | int n = 0; |
| 754 | for (ts = tb->hash[s]; ts; ts = gch(ts)->next) { | 754 | for (ts = tb->hash[s]; ts; ts = gch(ts)->next) { |
| 755 | setsvalue2s(L, L->top, rawgco2ts(ts)); | 755 | setsvalue2s(L, L->top, rawgco2ts(ts)); |
| 756 | incr_top(L); | 756 | api_incr_top(L); |
| 757 | n++; | 757 | n++; |
| 758 | } | 758 | } |
| 759 | return n; | 759 | return n; |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lvm.c,v 2.152 2012/06/08 15:14:04 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 2.153 2012/08/14 18:12:34 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 | */ |
| @@ -98,7 +98,6 @@ static void callTM (lua_State *L, const TValue *f, const TValue *p1, | |||
| 98 | setobj2s(L, L->top++, p2); /* 2nd argument */ | 98 | setobj2s(L, L->top++, p2); /* 2nd argument */ |
| 99 | if (!hasres) /* no result? 'p3' is third argument */ | 99 | if (!hasres) /* no result? 'p3' is third argument */ |
| 100 | setobj2s(L, L->top++, p3); /* 3rd argument */ | 100 | setobj2s(L, L->top++, p3); /* 3rd argument */ |
| 101 | luaD_checkstack(L, 0); | ||
| 102 | /* metamethod may yield only when called from Lua code */ | 101 | /* metamethod may yield only when called from Lua code */ |
| 103 | luaD_call(L, L->top - (4 - hasres), hasres, isLua(L->ci)); | 102 | luaD_call(L, L->top - (4 - hasres), hasres, isLua(L->ci)); |
| 104 | if (hasres) { /* if has result, move it to its place */ | 103 | if (hasres) { /* if has result, move it to its place */ |
