mirror of
https://github.com/lua/lua
synced 2024-11-22 04:41:23 +03:00
details
Minor optimizations in 'lvm.c'. (Not exactly optimizations, but more chances for optimizations.)
This commit is contained in:
parent
faaf7e481f
commit
3dcd04ad61
12
lvm.c
12
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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user