mirror of https://github.com/rusefi/lua.git
Calls 'luaF_close' in 'lua_settop' only when needed
In 'lua_settop', avoid calling 'luaF_close' when increasing the stack or when the function has no to-be-closed variables.
This commit is contained in:
parent
8082906c05
commit
9c28ed05c9
10
lapi.c
10
lapi.c
|
@ -170,12 +170,13 @@ LUA_API int lua_gettop (lua_State *L) {
|
||||||
|
|
||||||
|
|
||||||
LUA_API void lua_settop (lua_State *L, int idx) {
|
LUA_API void lua_settop (lua_State *L, int idx) {
|
||||||
StkId func = L->ci->func;
|
CallInfo *ci = L->ci;
|
||||||
int diff; /* difference for new top */
|
StkId func = ci->func;
|
||||||
|
ptrdiff_t diff; /* difference for new top */
|
||||||
lua_lock(L);
|
lua_lock(L);
|
||||||
if (idx >= 0) {
|
if (idx >= 0) {
|
||||||
api_check(L, idx <= L->ci->top - (func + 1), "new top too large");
|
api_check(L, idx <= ci->top - (func + 1), "new top too large");
|
||||||
diff = (func + 1) + idx - L->top;
|
diff = ((func + 1) + idx) - L->top;
|
||||||
for (; diff > 0; diff--)
|
for (; diff > 0; diff--)
|
||||||
setnilvalue(s2v(L->top++)); /* clear new slots */
|
setnilvalue(s2v(L->top++)); /* clear new slots */
|
||||||
}
|
}
|
||||||
|
@ -183,6 +184,7 @@ LUA_API void lua_settop (lua_State *L, int idx) {
|
||||||
api_check(L, -(idx+1) <= (L->top - (func + 1)), "invalid new top");
|
api_check(L, -(idx+1) <= (L->top - (func + 1)), "invalid new top");
|
||||||
diff = idx + 1; /* will "subtract" index (as it is negative) */
|
diff = idx + 1; /* will "subtract" index (as it is negative) */
|
||||||
}
|
}
|
||||||
|
if (diff < 0 && hastocloseCfunc(ci->nresults))
|
||||||
luaF_close(L, L->top + diff, LUA_OK);
|
luaF_close(L, L->top + diff, LUA_OK);
|
||||||
L->top += diff; /* correct top only after closing any upvalue */
|
L->top += diff; /* correct top only after closing any upvalue */
|
||||||
lua_unlock(L);
|
lua_unlock(L);
|
||||||
|
|
Loading…
Reference in New Issue