From 75dcc45c1589a5b42b8c24af448c1e7013bdf687 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Wed, 10 Jul 2024 10:36:35 +0200 Subject: [PATCH 10/17] In timefns, do gcd reduction more often MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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. --- 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.34.1