lua

A copy of the Lua development repository
Log | Files | Refs | README

commit c1de1fdac6a7873f8ae016785f364c5ae10abb1e
parent a36c8e1718fd32ea99e29797e5124600a16ccc03
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date:   Thu, 18 Jun 2009 13:36:16 -0300

small optimization in 'lua_arith' (avoids overhead in the common case
of both arguments being numbers)

Diffstat:
Mlapi.c | 8++++++--
1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/lapi.c b/lapi.c @@ -1,5 +1,5 @@ /* -** $Id: lapi.c,v 2.80 2009/06/17 17:52:57 roberto Exp roberto $ +** $Id: lapi.c,v 2.81 2009/06/17 18:38:54 roberto Exp roberto $ ** Lua API ** See Copyright Notice in lua.h */ @@ -278,7 +278,11 @@ LUA_API int lua_rawequal (lua_State *L, int index1, int index2) { LUA_API void lua_arith (lua_State *L, int op) { lua_lock(L); api_checknelems(L, 2); - luaV_arith(L, L->top - 2, L->top - 2, L->top - 1, op - LUA_OPADD + TM_ADD); + if (ttisnumber(L->top - 2) && ttisnumber(L->top - 1)) + changenvalue(L->top - 2, + luaO_arith(op, nvalue(L->top - 2), nvalue(L->top - 1))); + else + luaV_arith(L, L->top - 2, L->top - 2, L->top - 1, op - LUA_OPADD + TM_ADD); L->top--; lua_unlock(L); }