From a3e1c40d6d6fb81db9d8b58aee69466f715aab5c Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Thu, 16 Aug 2012 14:34:28 -0300 Subject: remove of unecessary luaD_checkstack. (In some cases, C should ensure stack space; in others, Lua can use the extra slots for temporary values.) --- lobject.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'lobject.c') diff --git a/lobject.c b/lobject.c index 86b3097e..11be7ad9 100644 --- a/lobject.c +++ b/lobject.c @@ -1,5 +1,5 @@ /* -** $Id: lobject.c,v 2.54 2011/11/30 12:44:26 roberto Exp roberto $ +** $Id: lobject.c,v 2.55 2011/11/30 19:30:16 roberto Exp roberto $ ** Some generic functions over Lua objects ** See Copyright Notice in lua.h */ @@ -171,8 +171,7 @@ int luaO_str2d (const char *s, size_t len, lua_Number *result) { static void pushstr (lua_State *L, const char *str, size_t l) { - setsvalue2s(L, L->top, luaS_newlstr(L, str, l)); - incr_top(L); + setsvalue2s(L, L->top++, luaS_newlstr(L, str, l)); } @@ -182,8 +181,8 @@ const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) { for (;;) { const char *e = strchr(fmt, '%'); if (e == NULL) break; - setsvalue2s(L, L->top, luaS_newlstr(L, fmt, e-fmt)); - incr_top(L); + luaD_checkstack(L, 2); /* fmt + item */ + pushstr(L, fmt, e - fmt); switch (*(e+1)) { case 's': { const char *s = va_arg(argp, char *); @@ -198,13 +197,11 @@ const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) { break; } case 'd': { - setnvalue(L->top, cast_num(va_arg(argp, int))); - incr_top(L); + setnvalue(L->top++, cast_num(va_arg(argp, int))); break; } case 'f': { - setnvalue(L->top, cast_num(va_arg(argp, l_uacNumber))); - incr_top(L); + setnvalue(L->top++, cast_num(va_arg(argp, l_uacNumber))); break; } case 'p': { @@ -226,6 +223,7 @@ const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) { n += 2; fmt = e+2; } + luaD_checkstack(L, 1); pushstr(L, fmt, strlen(fmt)); if (n > 0) luaV_concat(L, n + 1); return svalue(L->top - 1); -- cgit v1.2.3-55-g6feb