From 001147e1d3a37718c4b75c2d56ea475455707464 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Wed, 28 Feb 2024 19:09:58 -0800 Subject: seq_build: seq_pend must be nondestructive for lists. Let's have both a seq_pend and seq_nconc, where seq_nconc can reuse the pieces of list passed to it. * lib.h (struct seq_build_ops): New member, nconc. (seq_build_ops_init): Add nconc parameter and initializer. (seq_nconc): Function declared. * lib.c (seq_build_list_pend): Switch to list_collect_append, otherwise mappend behaves destructively. (seq_build_list_nconc): New function. (sb_vec_ops, sb_str_ops, sb_buf_ops, sb_struct_ops, sb_carray_ops): Use seq_build_generic_pend for nconc operation. (sb_list_ops): Use new seq_build_list_nconc for nconc operation. (sb_finished_ops): Use null pointer for nconc operation. (seq_nconc): New function. --- lib.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'lib.h') diff --git a/lib.h b/lib.h index f254ce6b..e3816473 100644 --- a/lib.h +++ b/lib.h @@ -483,12 +483,13 @@ typedef struct seq_build { struct seq_build_ops { void (*add)(struct seq_build *, val); void (*pend)(struct seq_build *, val); + void (*nconc)(struct seq_build *, val); void (*finish)(struct seq_build *); void (*mark)(struct seq_build *); }; -#define seq_build_ops_init(add, pend, finish, mark) \ - { add, pend, finish, mark } +#define seq_build_ops_init(add, pend, nconc, finish, mark) \ + { add, pend, nconc, finish, mark } extern const seq_kind_t seq_kind_tab[MAXTYPE+1]; @@ -768,6 +769,7 @@ val iter_reset(val iter, val obj); void seq_build_init(val self, seq_build_t *bu, val likeobj); void seq_add(seq_build_t *bu, val item); void seq_pend(seq_build_t *bu, val items); +void seq_nconc(seq_build_t *bu, val items); val seq_finish(seq_build_t *bu); NORETURN val throw_mismatch(val self, val obj, type_t); INLINE val type_check(val self, val obj, type_t typecode) -- cgit v1.2.3