From 96c884c1754058cbacd709be0de17559c1a3a2a6 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Sat, 2 Mar 2024 18:57:52 -0800 Subject: unique: covert to seq_build. * lib.c (unique): Build output using seq_build_t, rather than consing up a list which is then converted to the desired sequence type. --- lib.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib.c b/lib.c index 339fec2f..a1eb5881 100644 --- a/lib.c +++ b/lib.c @@ -11541,10 +11541,11 @@ val unique(val seq, val keyfun, varg hashv_args) val hash = hashv(hashv_args); val kf = default_arg(keyfun, identity_f); seq_iter_t iter; + seq_build_t build; val elem; - list_collect_decl (out, ptail); seq_iter_init(self, &iter, seq); + seq_build_init(self, &build, seq); while (seq_get(&iter, &elem)) { val new_p; @@ -11552,10 +11553,10 @@ val unique(val seq, val keyfun, varg hashv_args) (void) gethash_c(self, hash, funcall1(kf, elem), mkcloc(new_p)); if (new_p) - ptail = list_collect(ptail, elem); + seq_add(&build, elem); } - return make_like(out, seq); + return seq_finish(&build); } val uniq(val seq) -- cgit v1.2.3