From: Paul Eggert Date: Tue, 4 Sep 2018 17:24:51 +0000 (-0700) Subject: Tweak nthcdr for bignum efficiency X-Git-Tag: emacs-27.0.90~4467 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=628f6a2c7a9fe476b7e71efed3a8f8784a00cc54;p=emacs.git Tweak nthcdr for bignum efficiency * src/fns.c (Fnthcdr): Use mpz_tdiv_ui and mpz_tdiv_r instead of mpz_mod_ui and mpz_mod, as they are more efficient. Suggested by Pip Cet in: https://lists.gnu.org/r/emacs-devel/2018-09/msg00073.html --- diff --git a/src/fns.c b/src/fns.c index 8b25492eaeb..5a98f148818 100644 --- a/src/fns.c +++ b/src/fns.c @@ -1470,11 +1470,11 @@ DEFUN ("nthcdr", Fnthcdr, Snthcdr, 2, 2, 0, CYCLE_LENGTH. */ /* Add N mod CYCLE_LENGTH to NUM. */ if (cycle_length <= ULONG_MAX) - num += mpz_mod_ui (mpz[0], XBIGNUM (n)->value, cycle_length); + num += mpz_tdiv_ui (XBIGNUM (n)->value, cycle_length); else { mpz_set_intmax (mpz[0], cycle_length); - mpz_mod (mpz[0], XBIGNUM (n)->value, mpz[0]); + mpz_tdiv_r (mpz[0], XBIGNUM (n)->value, mpz[0]); intptr_t iz; mpz_export (&iz, NULL, -1, sizeof iz, 0, 0, mpz[0]); num += iz;