unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
From: David Kastrup <dak@gnu.org>
To: 22630@debbugs.gnu.org
Cc: David Kastrup <dak@gnu.org>
Subject: bug#22630: [PATCH] Let assv/assoc shortcircuit to assq where feasible
Date: Thu, 11 Feb 2016 12:31:48 +0100	[thread overview]
Message-ID: <1455190308-16788-1-git-send-email-dak@gnu.org> (raw)

	* libguile/alist.c (scm_sloppy_assv, scm_sloppy_assoc):
	Shortcircuit to scm_sloppy_assq where feasible
	(scm_assv, scm_assoc): Shortcircuit to scm_assq where feasible
---
 libguile/alist.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/libguile/alist.c b/libguile/alist.c
index f33aa41..e9bb80e 100644
--- a/libguile/alist.c
+++ b/libguile/alist.c
@@ -28,6 +28,7 @@
 
 #include "libguile/validate.h"
 #include "libguile/pairs.h"
+#include "libguile/numbers.h"
 #include "libguile/alist.h"
 
 \f
@@ -72,6 +73,12 @@ SCM_DEFINE (scm_sloppy_assv, "sloppy-assv", 2, 0, 0,
 	    "Recommended only for use in Guile internals.")
 #define FUNC_NAME s_scm_sloppy_assv
 {
+  /* Non-immediate numbers are the only keys we need to check
+   * other than with eq
+   */
+  if (!SCM_NUMP (key))
+    return scm_sloppy_assq (key, alist);
+
   for (; scm_is_pair (alist); alist = SCM_CDR (alist))
     {
       SCM tmp = SCM_CAR (alist);
@@ -90,6 +97,10 @@ SCM_DEFINE (scm_sloppy_assoc, "sloppy-assoc", 2, 0, 0,
 	    "Recommended only for use in Guile internals.")
 #define FUNC_NAME s_scm_sloppy_assoc
 {
+  /* Immediate values can be checked using eq */
+  if (SCM_IMP (key))
+    return scm_sloppy_assq (key, alist);
+
   for (; scm_is_pair (alist); alist = SCM_CDR (alist))
     {
       SCM tmp = SCM_CAR (alist);
@@ -139,6 +150,13 @@ SCM_DEFINE (scm_assv, "assv", 2, 0, 0,
 #define FUNC_NAME s_scm_assv
 {
   SCM ls = alist;
+
+  /* Non-immediate numbers are the only keys we need to check
+   * other than with eq
+   */
+  if (!SCM_NUMP (key))
+    return scm_assq (key, alist);
+
   for(; scm_is_pair (ls); ls = SCM_CDR (ls)) 
     {
       SCM tmp = SCM_CAR (ls);
@@ -160,6 +178,11 @@ SCM_DEFINE (scm_assoc, "assoc", 2, 0, 0,
 #define FUNC_NAME s_scm_assoc
 {
   SCM ls = alist;
+
+  /* Immediate values can be checked using eq */
+  if (SCM_IMP (key))
+    return scm_assq (key, alist);
+
   for(; scm_is_pair (ls); ls = SCM_CDR (ls)) 
     {
       SCM tmp = SCM_CAR (ls);
-- 
2.5.0






             reply	other threads:[~2016-02-11 11:31 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-11 11:31 David Kastrup [this message]
2016-08-07 20:53 ` bug#22630: [PATCH] Let assv/assoc shortcircuit to assq where feasible Andy Wingo
2016-10-11  9:03 ` bug#22630: Bad comment David Kastrup

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/guile/

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

  git send-email \
    --in-reply-to=1455190308-16788-1-git-send-email-dak@gnu.org \
    --to=dak@gnu.org \
    --cc=22630@debbugs.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.
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).