• Paul Eggert's avatar
    Speed up (nthcdr N L) when L is circular · eb83344f
    Paul Eggert authored
    Also, fix bug when N is a positive bignum, a problem reported
    by Eli Zaretskii and Pip Cet in:
    https://lists.gnu.org/r/emacs-devel/2018-08/msg00690.html
    * src/fns.c (Fnthcdr): If a cycle is found, reduce the count
    modulo the cycle length before continuing.  This reduces the
    worst-case cost of (nthcdr N L) from N to min(N, C) where C is
    the number of distinct cdrs of L.  Reducing modulo the cycle
    length also allows us to do arithmetic with machine words
    instead of with GMP.
    * test/src/fns-tests.el (test-nthcdr-circular): New test.
    eb83344f
fns.c 154 KB