From: Paul Eggert Date: Wed, 10 Jul 2024 08:36:35 +0000 (+0200) Subject: In timefns, do gcd reduction more often X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=8b461dc5e71b0991847747fe4b9e9c65c0592df8;p=emacs.git In timefns, do gcd reduction more often * 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) --- 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);