From 57c8e010cea8dfb8d0e6d54992a7543c640c4f9f Mon Sep 17 00:00:00 2001 From: Pip Cet Date: Thu, 27 Jun 2019 21:04:18 +0000 Subject: [PATCH] Make `equal' symmetric. * src/fns.c (internal_equal): Make symmetric. Copy tortoise-hare algorithm from lisp.h --- src/fns.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/fns.c b/src/fns.c index 2fc000a7f4..623435445a 100644 --- a/src/fns.c +++ b/src/fns.c @@ -2401,16 +2401,27 @@ internal_equal (Lisp_Object o1, Lisp_Object o2, enum equal_kind equal_kind, return true; } else - FOR_EACH_TAIL (o1) + for (struct for_each_tail_internal li1 = { o1, 2, 0, 2 }, + li2 = { o2, 2, 0, 2 }; + CONSP (o1) && CONSP (o2); + (o1 = XCDR (o1), + o2 = XCDR (o2), + ((--li1.q != 0 + || (maybe_quit (), 0 < --li1.n) + || (li1.q = li1.n = li1.max <<= 1, li1.n >>= USHRT_WIDTH, + li1.tortoise = (o1), false)) + && EQ (o1, li1.tortoise)) ? circular_list (o1) : (void) 0, + ((--li2.q != 0 + || (maybe_quit (), 0 < --li2.n) + || (li2.q = li2.n = li2.max <<= 1, li2.n >>= USHRT_WIDTH, + li2.tortoise = (o2), false)) + && EQ (o2, li2.tortoise)) ? circular_list (o2) : (void) 0)) { - if (! CONSP (o2)) - return false; + if (EQ (o1, o2)) + return true; if (! internal_equal (XCAR (o1), XCAR (o2), equal_kind, depth + 1, ht)) return false; - o2 = XCDR (o2); - if (EQ (XCDR (o1), o2)) - return true; } depth++; goto tail_recurse; -- 2.20.1