emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Emacs-diffs] master eb83344: Speed up (nthcdr N L) when L is circul


From: Pip Cet
Subject: Re: [Emacs-diffs] master eb83344: Speed up (nthcdr N L) when L is circular
Date: Tue, 21 Aug 2018 06:36:06 +0000

On Mon, Aug 20, 2018 at 11:01 PM Paul Eggert <address@hidden> wrote:
>     Speed up (nthcdr N L) when L is circular

...but slow it down when it isn't. May I suggest we fall back to the
old implementation for small n, maybe n <= 128 or something like that?

> +      if (tail == li.tortoise)
> +       tortoise_num = num;

I would prefer EQ (tail, li.tortoise) in the condition.

> +  /* TAIL is part of a cycle.  Reduce NUM modulo the cycle length to
> +     avoid going around this cycle repeatedly.  */
> +  intptr_t cycle_length = tortoise_num - num;

I'm unsure about this line. I might be being stupid, but it seems to
me tortoise_num is always num + 1, given the code above:

  FOR_EACH_TAIL_SAFE (tail)
    {
      if (num <= 0)
    return tail;
      if (tail == li.tortoise)
    tortoise_num = num;
      saved_tail = XCDR (tail);
      num--;
      rarely_quit (num);
    }

We exit this loop if EQ (tail, li.tortoise), in which case
tortoise_num = num + 1, or if !CONSP (tail), in which case we have
returned by the time we assign to cycle_length.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]