From c005ad21d1259ea8c984e0084fd8b71cff86ca4d Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Thu, 7 Mar 2024 20:19:35 -0800 Subject: rfind: use seq_iter. * lib.c (rfind): We combine the default case with SEQ_LISTLIKE and use the seq_iter abstraction rather than car/cdr. --- lib.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/lib.c b/lib.c index 93f05e93..9d4dfd34 100644 --- a/lib.c +++ b/lib.c @@ -11719,14 +11719,16 @@ val rfind(val item, val seq, val testfun_in, val keyfun_in) case SEQ_NIL: return nil; case SEQ_LISTLIKE: + default: { val found = nil; - gc_hint(seq); + val elem; + seq_iter_t it; - for (seq = z(si.obj); seq; seq = cdr(seq)) { - val elem = car(seq); - val key = funcall1(keyfun, elem); + seq_iter_init_with_info(self, &it, si, 0); + while (seq_get(&it, &elem)) { + val key = funcall1(keyfun, elem); if (funcall2(testfun, item, key)) found = elem; } @@ -11761,10 +11763,9 @@ val rfind(val item, val seq, val testfun_in, val keyfun_in) } break; } - return nil; - default: - unsup_obj(self, seq); + break; } + return nil; } val find_max(val seq, val testfun_in, val keyfun_in) -- cgit v1.2.3