core: equal2_p: Add short-circuit and eliminate tail call.

* src/lib.c (equal2_p): Add short-circuit and eliminate tail call.
This commit is contained in:
Jan Nieuwenhuizen 2018-04-24 06:59:18 +02:00
parent 9936aa383b
commit 4fa6acc480
No known key found for this signature in database
GPG key ID: F3C1A0D9C1D65273

View file

@ -293,14 +293,25 @@ memq (SCM x, SCM a)
SCM SCM
equal2_p (SCM a, SCM b) equal2_p (SCM a, SCM b)
{ {
if (a == cell_nil && b == cell_nil) equal2:
if (a == b)
return cell_t; return cell_t;
if (TYPE (a) == TPAIR && TYPE (b) == TPAIR) if (TYPE (a) == TPAIR && TYPE (b) == TPAIR)
return equal2_p (CAR (a), CAR (b)) == cell_t {
&& equal2_p (CDR (a), CDR (b)) == cell_t if (equal2_p (CAR (a), CAR (b)) == cell_t)
? cell_t : cell_f; {
a = CDR (a);
b = CDR (b);
goto equal2;
}
return cell_f;
}
if (TYPE (a) == TSTRING && TYPE (b) == TSTRING) if (TYPE (a) == TSTRING && TYPE (b) == TSTRING)
return equal2_p (STRING (a), STRING (b)); {
a = STRING (a);
b = STRING (b);
goto equal2;
}
if (TYPE (a) == TVECTOR && TYPE (b) == TVECTOR) if (TYPE (a) == TVECTOR && TYPE (b) == TVECTOR)
{ {
if (LENGTH (a) != LENGTH (b)) if (LENGTH (a) != LENGTH (b))