From 9f142b398f53ab7844a0fdfc5b562e8bbccfebe2 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Sun, 29 Aug 2021 06:31:49 -0700 Subject: seq_iter: refactoring. This is needed in preparation for fixing some gc bugs in iteration in a less hacky way. * lib.h (struct seq_iter): Members get and peek removed, replaced by ops pointer. (struct seq_iter_ops): New struct type. (seq_get, seq_peek): Call get and peek through ops table. * lib.c (seq_geti): Refer to get through ops. (si_null_ops, si_list_ops, si_vec_ops, si_hash_ops, si_tree_ops, si_range_cnum_ops, si_range_chr_ops, si_range_bignum_ops, si_range_str_ops, si_rev_range_cnum_ops, si_rev_range_chr_ops, si_rev_range_bignum_ops, si_rev_range_str_ops, si_chr_ops, si_num_ops, si_oop_ops, si_fast_oop_ops): New static structures. (seq_iter_init_with_info): Point new ops member of seq_iter to one of the new structures. Remove initializations of get and peek. --- lib.h | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'lib.h') diff --git a/lib.h b/lib.h index 5fa529e5..3365183c 100644 --- a/lib.h +++ b/lib.h @@ -415,9 +415,15 @@ typedef struct seq_iter { cnum cbound; val next; } ul; + struct seq_iter_ops *ops; +} seq_iter_t; + +struct seq_iter_ops { int (*get)(struct seq_iter *, val *pval); int (*peek)(struct seq_iter *, val *pval); -} seq_iter_t; +}; + +#define seq_iter_ops_init(get, peek) { get, peek } extern const seq_kind_t seq_kind_tab[MAXTYPE+1]; @@ -572,8 +578,8 @@ seq_info_t seq_info(val cobj); void seq_iter_init_with_info(val self, seq_iter_t *it, seq_info_t si, int support_rewind); void seq_iter_init(val self, seq_iter_t *it, val obj); -INLINE int seq_get(seq_iter_t *it, val *pval) { return it->get(it, pval); } -INLINE int seq_peek(seq_iter_t *it, val *pval) { return it->peek(it, pval); } +INLINE int seq_get(seq_iter_t *it, val *pval) { return it->ops->get(it, pval); } +INLINE int seq_peek(seq_iter_t *it, val *pval) { return it->ops->peek(it, pval); } val seq_geti(seq_iter_t *it); val seq_getpos(val self, seq_iter_t *it); void seq_setpos(val self, seq_iter_t *it, val pos); -- cgit v1.2.3