remove of unecessary luaD_checkstack. (In some cases, C should
ensure stack space; in others, Lua can use the extra slots for temporary values.)
This commit is contained in:
16
lobject.c
16
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);
|
||||
|
||||
Reference in New Issue
Block a user