summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2019-09-20 07:47:16 -0700
committerKaz Kylheku <kaz@kylheku.com>2019-09-20 07:47:16 -0700
commit554b057caad84f47dafc5d540aaf4880f30d23a5 (patch)
treede34f9fd89a67ad6925ab4b0da3b575ab3527b4c
parent14848e09a6b9ba1c838ee406f1eb23875006b0ca (diff)
downloadtxr-554b057caad84f47dafc5d540aaf4880f30d23a5.tar.gz
txr-554b057caad84f47dafc5d540aaf4880f30d23a5.tar.bz2
txr-554b057caad84f47dafc5d540aaf4880f30d23a5.zip
equal: reduce type checking for conses.
* lib.c (equal): Since we have switched on the type of the left and right argument, we can access the object directly instead of going through car and cdr. Except that for a lazy conses, we need at least one such access to force the object first.
-rw-r--r--lib.c25
1 files changed, 22 insertions, 3 deletions
diff --git a/lib.c b/lib.c
index 862bb1ce..ebea0d00 100644
--- a/lib.c
+++ b/lib.c
@@ -2681,12 +2681,31 @@ val equal(val left, val right)
case NUM:
break;
case CONS:
+ switch (type(right)) {
+ case CONS:
+ if (equal(left->c.car, right->c.car) && equal(left->c.cdr, right->c.cdr))
+ return t;
+ return nil;
+ case LCONS:
+ if (equal(left->c.car, car(right)) && equal(left->c.cdr, right->c.cdr))
+ return t;
+ return nil;
+ default:
+ break;
+ }
+ return nil;
case LCONS:
- if (type(right) == CONS || type(right) == LCONS)
- {
- if (equal(car(left), car(right)) && equal(cdr(left), cdr(right)))
+ switch (type(right)) {
+ case CONS:
+ if (equal(car(left), right->c.car) && equal(left->c.cdr, right->c.cdr))
return t;
return nil;
+ case LCONS:
+ if (equal(car(left), car(right)) && equal(left->c.cdr, right->c.cdr))
+ return t;
+ return nil;
+ default:
+ break;
}
break;
case LIT: