aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert2018-09-04 10:24:51 -0700
committerPaul Eggert2018-09-04 10:25:11 -0700
commit628f6a2c7a9fe476b7e71efed3a8f8784a00cc54 (patch)
treedb0acf740fb86590b5be540e262cc6d0e3b79257 /src
parent1d84e6523250ab6d14f40fba3922c56d7a40416f (diff)
downloademacs-628f6a2c7a9fe476b7e71efed3a8f8784a00cc54.tar.gz
emacs-628f6a2c7a9fe476b7e71efed3a8f8784a00cc54.zip
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
Diffstat (limited to 'src')
-rw-r--r--src/fns.c4
1 files changed, 2 insertions, 2 deletions
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,
1470 CYCLE_LENGTH. */ 1470 CYCLE_LENGTH. */
1471 /* Add N mod CYCLE_LENGTH to NUM. */ 1471 /* Add N mod CYCLE_LENGTH to NUM. */
1472 if (cycle_length <= ULONG_MAX) 1472 if (cycle_length <= ULONG_MAX)
1473 num += mpz_mod_ui (mpz[0], XBIGNUM (n)->value, cycle_length); 1473 num += mpz_tdiv_ui (XBIGNUM (n)->value, cycle_length);
1474 else 1474 else
1475 { 1475 {
1476 mpz_set_intmax (mpz[0], cycle_length); 1476 mpz_set_intmax (mpz[0], cycle_length);
1477 mpz_mod (mpz[0], XBIGNUM (n)->value, mpz[0]); 1477 mpz_tdiv_r (mpz[0], XBIGNUM (n)->value, mpz[0]);
1478 intptr_t iz; 1478 intptr_t iz;
1479 mpz_export (&iz, NULL, -1, sizeof iz, 0, 0, mpz[0]); 1479 mpz_export (&iz, NULL, -1, sizeof iz, 0, 0, mpz[0]);
1480 num += iz; 1480 num += iz;