unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Alex Gramiak <agrambot@gmail.com>
To: Paul Eggert <eggert@cs.ucla.edu>
Cc: Eli Zaretskii <eliz@gnu.org>, emacs-devel@gnu.org
Subject: Using SMALL_LIST_LEN_MAX for memq and list_length (was: [RFC] Some new vector procedures (vector-{memq, apply, to-string, ...}))
Date: Sat, 20 Apr 2019 21:01:13 -0600	[thread overview]
Message-ID: <8736mc6ozq.fsf_-_@gmail.com> (raw)
In-Reply-To: <ce8e3728-ccf7-de87-8fdc-fad9e404cc32@cs.ucla.edu> (Paul Eggert's message of "Sat, 20 Apr 2019 15:54:50 -0700")

[-- Attachment #1: Type: text/plain, Size: 412 bytes --]

Paul Eggert <eggert@cs.ucla.edu> writes:

> We could probably speed up the cycle checking somewhat, but that's a different
> topic.

On that topic, I recently tried using SMALL_LIST_LEN_MAX for memq and
list_length similarly to nth/elt. WDYT? For small lists it seems to be
faster, but for longer lists it seems to be slower (maybe that's due to
the branch predictor in my simple benchmark-run-compiled tests).


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: memq --]
[-- Type: text/x-patch, Size: 582 bytes --]

diff --git a/src/fns.c b/src/fns.c
index c3202495da..267bd2c40f 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -1557,9 +1557,18 @@ The value is actually the tail of LIST whose car is ELT.  */)
   (Lisp_Object elt, Lisp_Object list)
 {
   Lisp_Object tail = list;
+  for (int i = 0; i < SMALL_LIST_LEN_MAX; ++i, tail = XCDR (tail))
+    {
+      if (!CONSP (tail))
+        goto end;
+      else if (EQ (XCAR (tail), elt))
+        return tail;
+    }
+
   FOR_EACH_TAIL (tail)
     if (EQ (XCAR (tail), elt))
       return tail;
+ end:
   CHECK_LIST_END (tail, list);
   return Qnil;
 }

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: list_length --]
[-- Type: text/x-patch, Size: 383 bytes --]

diff --git a/src/fns.c b/src/fns.c
index c3202495da..b7f25d4cba 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -97,6 +97,11 @@ ptrdiff_t
 list_length (Lisp_Object list)
 {
   intptr_t i = 0;
+  for ( ; i < SMALL_LIST_LEN_MAX && CONSP (list); ++i, list = XCDR (list))
+    ;
+  if (i < SMALL_LIST_LEN_MAX)
+    return i;
+
   FOR_EACH_TAIL (list)
     i++;
   CHECK_LIST_END (list, list);

  reply	other threads:[~2019-04-21  3:01 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-19 20:49 [RFC] Some new vector procedures (vector-{memq, apply, to-string, ...}) Alex Gramiak
2019-04-20  7:04 ` Eli Zaretskii
2019-04-20 16:50   ` Alex Gramiak
2019-04-20 17:16     ` Eli Zaretskii
2019-04-20 18:18       ` Alex Gramiak
2019-04-20 19:11         ` Eli Zaretskii
2019-04-20 19:54           ` Alan Mackenzie
2019-04-20 20:09             ` Óscar Fuentes
2019-04-20 22:54           ` Paul Eggert
2019-04-21  3:01             ` Alex Gramiak [this message]
2019-04-21  1:52           ` Alex Gramiak
2019-04-21  5:50             ` Eli Zaretskii
2019-04-21  4:05     ` Stefan Monnier
2019-04-21 20:34       ` Alex Gramiak
2019-04-21 21:01         ` Stefan Monnier

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=8736mc6ozq.fsf_-_@gmail.com \
    --to=agrambot@gmail.com \
    --cc=eggert@cs.ucla.edu \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@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).