From 8b461dc5e71b0991847747fe4b9e9c65c0592df8 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Wed, 10 Jul 2024 10:36:35 +0200 Subject: [PATCH] In timefns, do gcd reduction more often MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit * src/timefns.c (ticks_hz_hz_ticks): Reduce by gcd even if t.ticks is not a fixnum, since that’s easy. (cherry picked from commit b6cbf0cbb66fa4c1a7f351350d5f9aed9c93cd26) --- src/timefns.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/timefns.c b/src/timefns.c index 0df7d1f4363..ba1ba10a809 100644 --- a/src/timefns.c +++ b/src/timefns.c @@ -774,8 +774,8 @@ ticks_hz_hz_ticks (struct ticks_hz t, Lisp_Object hz) if (XFIXNUM (hz) <= 0) invalid_hz (hz); - /* For speed, use intmax_t arithmetic if it will do. */ - if (FASTER_TIMEFNS && FIXNUMP (t.ticks) && FIXNUMP (t.hz)) + /* Prefer non-bignum arithmetic to speed up common cases. */ + if (FASTER_TIMEFNS && FIXNUMP (t.hz)) { /* Reduce T.hz and HZ by their GCD, to avoid some intmax_t overflows that would occur in T.ticks * HZ. */ @@ -784,9 +784,12 @@ ticks_hz_hz_ticks (struct ticks_hz t, Lisp_Object hz) ithz /= d; ihz /= d; - intmax_t ticks; - if (!ckd_mul (&ticks, XFIXNUM (t.ticks), ihz)) - return make_int (ticks / ithz - (ticks % ithz < 0)); + if (FIXNUMP (t.ticks)) + { + intmax_t ticks; + if (!ckd_mul (&ticks, XFIXNUM (t.ticks), ihz)) + return make_int (ticks / ithz - (ticks % ithz < 0)); + } t.hz = make_fixnum (ithz); hz = make_fixnum (ihz); -- 2.39.2