From 3dcd04ad610d151afbe8cd92c43e2232e621fbb5 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Fri, 17 Aug 2018 15:53:39 -0300 Subject: [PATCH] details Minor optimizations in 'lvm.c'. (Not exactly optimizations, but more chances for optimizations.) --- lvm.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lvm.c b/lvm.c index 4e4ef270..7550dcc8 100644 --- a/lvm.c +++ b/lvm.c @@ -1,5 +1,5 @@ /* -** $Id: lvm.c,v 2.359 2018/06/18 17:58:21 roberto Exp roberto $ +** $Id: lvm.c $ ** Lua virtual machine ** See Copyright Notice in lua.h */ @@ -621,8 +621,8 @@ void luaV_objlen (lua_State *L, StkId ra, const TValue *rb) { ** otherwise 'floor(q) == trunc(q) - 1'. */ lua_Integer luaV_div (lua_State *L, lua_Integer m, lua_Integer n) { - if (l_castS2U(n) + 1u <= 1u) { /* special cases: -1 or 0 */ - if (unlikely(n == 0)) + if (unlikely(l_castS2U(n) + 1u <= 1u)) { /* special cases: -1 or 0 */ + if (n == 0) luaG_runerror(L, "attempt to divide by zero"); return intop(-, 0, m); /* n==-1; avoid overflow with 0x80000...//-1 */ } @@ -641,14 +641,14 @@ lua_Integer luaV_div (lua_State *L, lua_Integer m, lua_Integer n) { ** about luaV_div.) */ lua_Integer luaV_mod (lua_State *L, lua_Integer m, lua_Integer n) { - if (l_castS2U(n) + 1u <= 1u) { /* special cases: -1 or 0 */ - if (unlikely(n == 0)) + if (unlikely(l_castS2U(n) + 1u <= 1u)) { /* special cases: -1 or 0 */ + if (n == 0) luaG_runerror(L, "attempt to perform 'n%%0'"); return 0; /* m % -1 == 0; avoid overflow with 0x80000...%-1 */ } else { lua_Integer r = m % n; - if (r != 0 && (m ^ n) < 0) /* 'm/n' would be non-integer negative? */ + if (r != 0 && (r ^ n) < 0) /* 'm/n' would be non-integer negative? */ r += n; /* correct result for different rounding */ return r; }