From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: David Kastrup Newsgroups: gmane.lisp.guile.bugs Subject: bug#22630: [PATCH] Let assv/assoc shortcircuit to assq where feasible Date: Thu, 11 Feb 2016 12:31:48 +0100 Message-ID: <1455190308-16788-1-git-send-email-dak@gnu.org> NNTP-Posting-Host: plane.gmane.org X-Trace: ger.gmane.org 1455190400 15906 80.91.229.3 (11 Feb 2016 11:33:20 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 11 Feb 2016 11:33:20 +0000 (UTC) Cc: David Kastrup To: 22630@debbugs.gnu.org Original-X-From: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Thu Feb 11 12:33:10 2016 Return-path: Envelope-to: guile-bugs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1aTpUj-0005eQ-6P for guile-bugs@m.gmane.org; Thu, 11 Feb 2016 12:33:09 +0100 Original-Received: from localhost ([::1]:48923 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aTpUi-0007Qc-6e for guile-bugs@m.gmane.org; Thu, 11 Feb 2016 06:33:08 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:47188) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aTpUd-0007QQ-MM for bug-guile@gnu.org; Thu, 11 Feb 2016 06:33:04 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aTpUc-0003LA-MC for bug-guile@gnu.org; Thu, 11 Feb 2016 06:33:03 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:54809) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aTpUc-0003L5-J1 for bug-guile@gnu.org; Thu, 11 Feb 2016 06:33:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84) (envelope-from ) id 1aTpUc-0002C1-Ci for bug-guile@gnu.org; Thu, 11 Feb 2016 06:33:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: David Kastrup Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Thu, 11 Feb 2016 11:33:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 22630 X-GNU-PR-Package: guile X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-guile@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.14551903338366 (code B ref -1); Thu, 11 Feb 2016 11:33:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 11 Feb 2016 11:32:13 +0000 Original-Received: from localhost ([127.0.0.1]:35717 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aTpTp-0002As-JY for submit@debbugs.gnu.org; Thu, 11 Feb 2016 06:32:13 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:56041) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aTpTn-0002AG-Ut for submit@debbugs.gnu.org; Thu, 11 Feb 2016 06:32:12 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aTpTb-0002w7-Ry for submit@debbugs.gnu.org; Thu, 11 Feb 2016 06:32:00 -0500 Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:53390) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aTpTb-0002w3-PL for submit@debbugs.gnu.org; Thu, 11 Feb 2016 06:31:59 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:47006) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aTpTa-0007Kw-N7 for bug-guile@gnu.org; Thu, 11 Feb 2016 06:31:59 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aTpTZ-0002vW-LG for bug-guile@gnu.org; Thu, 11 Feb 2016 06:31:58 -0500 Original-Received: from fencepost.gnu.org ([2001:4830:134:3::e]:53489) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aTpTZ-0002vL-Hd for bug-guile@gnu.org; Thu, 11 Feb 2016 06:31:57 -0500 Original-Received: from localhost ([127.0.0.1]:49918 helo=lola) by fencepost.gnu.org with esmtp (Exim 4.82) (envelope-from ) id 1aTpTW-0001Kj-SV; Thu, 11 Feb 2016 06:31:55 -0500 Original-Received: by lola (Postfix, from userid 1000) id 3CE49DF5B8; Thu, 11 Feb 2016 12:31:54 +0100 (CET) X-Mailer: git-send-email 2.5.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-guile@gnu.org List-Id: "Bug reports for GUILE, GNU's Ubiquitous Extension Language" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Original-Sender: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.bugs:7959 Archived-At: * 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" @@ -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