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:
parent
9936aa383b
commit
4fa6acc480
21
src/lib.c
21
src/lib.c
|
@ -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))
|
||||||
|
|
Loading…
Reference in a new issue