This is the mail archive of the
guile@sourceware.cygnus.com
mailing list for the Guile project.
Patch
- To: "Greg J. Badros" <gjb at cs dot washington dot edu>, Guile Mailing List <guile at sourceware dot cygnus dot com>
- Subject: Patch
- From: Dirk Herrmann <dirk at ida dot ing dot tu-bs dot de>
- Date: Thu, 6 Jan 2000 14:18:17 +0100 (MET)
Hi.
When looking at alist.c, I realized some places that could be
improved. I have not gone through all of it, though. I intend to look at
guile in small units, as my time allows, so please forgive that I send
patches in small units.
===================================================================
RCS file: /cvs/guile/guile/guile-core/libguile/alist.c,v
retrieving revision 1.15
diff -u -p -r1.15 alist.c
--- alist.c 2000/01/05 19:25:35 1.15
+++ alist.c 2000/01/06 13:09:47
@@ -147,12 +147,14 @@ predicate is in use), then @code{#f} is
return the entire alist entry found (i.e. both the key and the value).")
#define FUNC_NAME s_scm_assq
{
- SCM tmp;
- for(;SCM_NIMP(alist);alist = SCM_CDR(alist)) {
- SCM_VALIDATE_ALISTCELL_COPYSCM (2,alist,tmp);
- if (SCM_CAR(tmp)==key) return tmp;
- }
- SCM_VALIDATE_NULL (2,alist);
+ for (; SCM_CONSP(alist); alist = SCM_CDR(alist))
+ {
+ SCM tmp = SCM_CAR(alist);
+ SCM_VALIDATE_CONS(2, tmp);
+ if (SCM_CAR(tmp) == key)
+ return tmp;
+ }
+ SCM_VALIDATE_NULL(2, alist);
return SCM_BOOL_F;
}
#undef FUNC_NAME
@@ -163,17 +165,14 @@ SCM_DEFINE (scm_assv, "assv", 2, 0, 0,
"Behaves like @code{assq} but uses @code{eqv?} for key comparison.")
#define FUNC_NAME s_scm_assv
{
- SCM tmp;
- for(;SCM_NIMP(alist);alist = SCM_CDR(alist)) {
- SCM_ASRTGO(SCM_CONSP(alist), badlst);
- tmp = SCM_CAR(alist);
- SCM_ASRTGO(SCM_CONSP(tmp), badlst);
- if SCM_NFALSEP(scm_eqv_p(SCM_CAR(tmp), key)) return tmp;
- }
-# ifndef SCM_RECKLESS
- if (!(SCM_NULLP(alist)))
- badlst: SCM_WTA(2,alist);
-# endif
+ for(; SCM_CONSP(alist); alist = SCM_CDR(alist))
+ {
+ SCM tmp = SCM_CAR(alist);
+ SCM_VALIDATE_CONS(2, tmp);
+ if SCM_NFALSEP(scm_eqv_p(SCM_CAR(tmp), key))
+ return tmp;
+ }
+ SCM_VALIDATE_NULL(2, alist);
return SCM_BOOL_F;
}
#undef FUNC_NAME
@@ -184,12 +183,14 @@ SCM_DEFINE (scm_assoc, "assoc", 2, 0, 0,
"Behaves like @code{assq} but uses @code{equal?} for key comparison.")
#define FUNC_NAME s_scm_assoc
{
- SCM tmp;
- for(;SCM_NIMP(alist);alist = SCM_CDR(alist)) {
- SCM_VALIDATE_ALISTCELL_COPYSCM (2,alist,tmp);
- if SCM_NFALSEP(scm_equal_p(SCM_CAR(tmp), key)) return tmp;
- }
- SCM_VALIDATE_NULL (2,alist);
+ for(; SCM_CONSP(alist); alist = SCM_CDR(alist))
+ {
+ SCM tmp = SCM_CAR(alist);
+ SCM_VALIDATE_CONS(2, tmp);
+ if SCM_NFALSEP(scm_equal_p(SCM_CAR(tmp), key))
+ return tmp;
+ }
+ SCM_VALIDATE_NULL(2, alist);
return SCM_BOOL_F;
}
#undef FUNC_NAME
* The scope of the tmp variables is minimized.
* The tmp variables are initialized at the same moment they are declared.
* The strange SCM_NIMP tests are replaced by SCM_CONSP tests that more closely
reflect the intended semantics. However, we don't get a performance penalty
here, because the SCM_CONSP test was performed by the ALISTCELL test anyway.
* The extremely ugly use of ASRTGO macros was removed: The calls to ASRTGO
were not encapsulated by "#ifndef SCM_RECKLESS", but got a label parameter
that only exists when SCM_RECKLESS is not defined. This works, because
ASRTGO itself is defined in a way that it only makes use of the label
parameter if SCM_RECKLESS is not defined (shudder!). Does guile make at all
use of the possibility to define SCM_RECKLESS?
* Codesize is likely to be reduced, since instead of two calls to SCM_ASSERT
performed by the ALISTCELL test we now only get one test.
Best regards
Dirk Herrmann