From 5205f073c57ae4b69e90d35c02e3a1a1cca44eb4 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Wed, 24 Feb 2021 12:24:42 -0300 Subject: Don't use tointegerns when luaV_tointegerns will do Some places don't need the "fast path" macro tointegerns, either because speed is not essential (lcode.c) or because the value is not supposed to be an integer already (luaV_equalobj and luaG_tointerror). Moreover, luaV_equalobj should always use F2Ieq, even if Lua is compiled to "round to floor". --- lvm.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'lvm.c') diff --git a/lvm.c b/lvm.c index c0a10d6c..c9729bcc 100644 --- a/lvm.c +++ b/lvm.c @@ -568,8 +568,13 @@ int luaV_equalobj (lua_State *L, const TValue *t1, const TValue *t2) { if (ttype(t1) != ttype(t2) || ttype(t1) != LUA_TNUMBER) return 0; /* only numbers can be equal with different variants */ else { /* two numbers with different variants */ - lua_Integer i1, i2; /* compare them as integers */ - return (tointegerns(t1, &i1) && tointegerns(t2, &i2) && i1 == i2); + /* One of them is an integer. If the other does not have an + integer value, they cannot be equal; otherwise, compare their + integer values. */ + lua_Integer i1, i2; + return (luaV_tointegerns(t1, &i1, F2Ieq) && + luaV_tointegerns(t2, &i2, F2Ieq) && + i1 == i2); } } /* values have same type and same variant */ -- cgit v1.2.3-55-g6feb