when running Lua code, there is no need to keep 'L->top' "correct";

set it only when needed.
This commit is contained in:
Roberto Ierusalimschy
2017-12-20 12:58:05 -02:00
parent 4dc0be950a
commit 1d5b885437
5 changed files with 53 additions and 41 deletions

View File

@@ -1,5 +1,5 @@
/*
** $Id: ldebug.c,v 2.148 2017/12/13 18:32:09 roberto Exp roberto $
** $Id: ldebug.c,v 2.149 2017/12/15 13:07:10 roberto Exp roberto $
** Debug Interface
** See Copyright Notice in lua.h
*/
@@ -189,14 +189,10 @@ static const char *upvalname (Proto *p, int uv) {
static const char *findlocal (lua_State *L, CallInfo *ci, int n,
StkId *pos) {
const char *name = NULL;
StkId base;
if (isLua(ci)) {
base = ci->func + 1;
name = luaF_getlocalname(ci_func(ci)->p, n, currentpc(ci));
}
else
base = ci->func + 1;
StkId base = ci->func + 1;
const char *name = (isLua(ci))
? luaF_getlocalname(ci_func(ci)->p, n, currentpc(ci))
: NULL;
if (name == NULL) { /* no 'standard' name? */
StkId limit = (ci == L->ci) ? L->top : ci->next->func;
if (limit - base >= n && n > 0) /* is 'n' inside 'ci' stack? */
@@ -741,6 +737,8 @@ l_noret luaG_runerror (lua_State *L, const char *fmt, ...) {
const char *msg;
va_list argp;
luaC_checkGC(L); /* error message uses memory */
if (isLuacode(ci))
L->top = ci->top; /* prepare top */
va_start(argp, fmt);
msg = luaO_pushvfstring(L, fmt, argp); /* format message */
va_end(argp);
@@ -764,6 +762,7 @@ static int changedline (Proto *p, int oldpc, int newpc) {
void luaG_traceexec (lua_State *L) {
ptrdiff_t oldtop = savestack(L, L->top);
CallInfo *ci = L->ci;
lu_byte mask = L->hookmask;
int counthook = (--L->hookcount == 0 && (mask & LUA_MASKCOUNT));
@@ -775,6 +774,7 @@ void luaG_traceexec (lua_State *L) {
ci->callstatus &= ~CIST_HOOKYIELD; /* erase mark */
return; /* do not call hook again (VM yielded, so it did not move) */
}
L->top = ci->top; /* prepare top */
if (counthook)
luaD_hook(L, LUA_HOOKCOUNT, -1); /* call count hook */
if (mask & LUA_MASKLINE) {
@@ -789,6 +789,7 @@ void luaG_traceexec (lua_State *L) {
}
L->oldpc = npc;
}
L->top = restorestack(L, oldtop);
if (L->status == LUA_YIELD) { /* did hook yield? */
if (counthook)
L->hookcount = 1; /* undo decrement to zero */