]> git.eshelyaron.com Git - emacs.git/commitdiff
Tweak nthcdr for bignum efficiency
authorPaul Eggert <eggert@cs.ucla.edu>
Tue, 4 Sep 2018 17:24:51 +0000 (10:24 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Tue, 4 Sep 2018 17:25:11 +0000 (10:25 -0700)
* 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

src/fns.c

index 8b25492eaeb867fbcfcdb7acc788bf6088bb0e09..5a98f1488185bf7e791acbb170a3e6b512c25de2 100644 (file)
--- 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;