unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Pip Cet <pipcet@gmail.com>
To: emacs-devel@gnu.org, eggert@cs.ucla.edu
Cc: emacs-diffs@gnu.org
Subject: Re: [Emacs-diffs] master eb83344: Speed up (nthcdr N L) when L is circular
Date: Tue, 21 Aug 2018 06:36:06 +0000	[thread overview]
Message-ID: <CAOqdjBePENHTTVyXkxw_JBd-iN1eXJMuyj1AXnC5WGmzXKHEUw@mail.gmail.com> (raw)
In-Reply-To: <20180820230136.541D8204F3@vcs0.savannah.gnu.org>

On Mon, Aug 20, 2018 at 11:01 PM Paul Eggert <eggert@cs.ucla.edu> 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.



  parent reply	other threads:[~2018-08-21  6:36 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20180820230135.12359.43125@vcs0.savannah.gnu.org>
     [not found] ` <20180820230136.541D8204F3@vcs0.savannah.gnu.org>
2018-08-21  2:05   ` master eb83344: Speed up (nthcdr N L) when L is circular Glenn Morris
2018-08-21  6:36   ` Pip Cet [this message]
2018-08-21  7:42     ` [Emacs-diffs] " Pip Cet
2018-08-21  9:10       ` Paul Eggert

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAOqdjBePENHTTVyXkxw_JBd-iN1eXJMuyj1AXnC5WGmzXKHEUw@mail.gmail.com \
    --to=pipcet@gmail.com \
    --cc=eggert@cs.ucla.edu \
    --cc=emacs-devel@gnu.org \
    --cc=emacs-diffs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).