mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-05-20 11:40:18 +02:00
Let assv/assoc shortcircuit to assq where feasible
* libguile/alist.c (scm_sloppy_assv, scm_sloppy_assoc): (scm_assv, scm_assoc): Shortcircuit to scm_assq where feasible.
This commit is contained in:
parent
8ad67667f3
commit
469970d4b3
1 changed files with 21 additions and 0 deletions
|
@ -28,6 +28,7 @@
|
||||||
|
|
||||||
#include "libguile/validate.h"
|
#include "libguile/validate.h"
|
||||||
#include "libguile/pairs.h"
|
#include "libguile/pairs.h"
|
||||||
|
#include "libguile/numbers.h"
|
||||||
#include "libguile/alist.h"
|
#include "libguile/alist.h"
|
||||||
|
|
||||||
|
|
||||||
|
@ -70,6 +71,11 @@ SCM_DEFINE (scm_sloppy_assv, "sloppy-assv", 2, 0, 0,
|
||||||
"Recommended only for use in Guile internals.")
|
"Recommended only for use in Guile internals.")
|
||||||
#define FUNC_NAME s_scm_sloppy_assv
|
#define FUNC_NAME s_scm_sloppy_assv
|
||||||
{
|
{
|
||||||
|
/* In Guile, `assv' is the same as `assq' for keys of all types except
|
||||||
|
numbers. */
|
||||||
|
if (!SCM_NUMP (key))
|
||||||
|
return scm_sloppy_assq (key, alist);
|
||||||
|
|
||||||
for (; scm_is_pair (alist); alist = SCM_CDR (alist))
|
for (; scm_is_pair (alist); alist = SCM_CDR (alist))
|
||||||
{
|
{
|
||||||
SCM tmp = SCM_CAR (alist);
|
SCM tmp = SCM_CAR (alist);
|
||||||
|
@ -88,6 +94,10 @@ SCM_DEFINE (scm_sloppy_assoc, "sloppy-assoc", 2, 0, 0,
|
||||||
"Recommended only for use in Guile internals.")
|
"Recommended only for use in Guile internals.")
|
||||||
#define FUNC_NAME s_scm_sloppy_assoc
|
#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))
|
for (; scm_is_pair (alist); alist = SCM_CDR (alist))
|
||||||
{
|
{
|
||||||
SCM tmp = SCM_CAR (alist);
|
SCM tmp = SCM_CAR (alist);
|
||||||
|
@ -137,6 +147,12 @@ SCM_DEFINE (scm_assv, "assv", 2, 0, 0,
|
||||||
#define FUNC_NAME s_scm_assv
|
#define FUNC_NAME s_scm_assv
|
||||||
{
|
{
|
||||||
SCM ls = alist;
|
SCM ls = alist;
|
||||||
|
|
||||||
|
/* In Guile, `assv' is the same as `assq' for keys of all types except
|
||||||
|
numbers. */
|
||||||
|
if (!SCM_NUMP (key))
|
||||||
|
return scm_assq (key, alist);
|
||||||
|
|
||||||
for(; scm_is_pair (ls); ls = SCM_CDR (ls))
|
for(; scm_is_pair (ls); ls = SCM_CDR (ls))
|
||||||
{
|
{
|
||||||
SCM tmp = SCM_CAR (ls);
|
SCM tmp = SCM_CAR (ls);
|
||||||
|
@ -158,6 +174,11 @@ SCM_DEFINE (scm_assoc, "assoc", 2, 0, 0,
|
||||||
#define FUNC_NAME s_scm_assoc
|
#define FUNC_NAME s_scm_assoc
|
||||||
{
|
{
|
||||||
SCM ls = alist;
|
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))
|
for(; scm_is_pair (ls); ls = SCM_CDR (ls))
|
||||||
{
|
{
|
||||||
SCM tmp = SCM_CAR (ls);
|
SCM tmp = SCM_CAR (ls);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue