Skip to content

Commit 1f25f5e

Browse files
committed
more cleanup
1 parent 0713073 commit 1f25f5e

File tree

2 files changed

+19
-29
lines changed

2 files changed

+19
-29
lines changed

src/array.h

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,10 @@ struct array {
189189
}
190190
}
191191

192-
inline array_p atom_i(size_t i) const { return atom(t, data_i(i)); }
192+
inline array_p atom_i(size_t i) const {
193+
if (t == T_ARR) return data<arr_t>()[i];
194+
else return atom(t, data_i(i));
195+
}
193196
inline array_p tail() const { return create(t, n - 1, data_i(1)); }
194197
};
195198

@@ -204,12 +207,3 @@ using array_p = rc<array>;
204207

205208
#define DO_MUT_ARRAY(a, typ, i, p) _DO_ARRAY_IMPL(a, i, p, UNIQUE(__), auto& p = a->mut_data<typ>()[i])
206209
#define DO_ARRAY(a, t, i, p) _DO_ARRAY_IMPL(a, i, p, UNIQUE(__), auto p = a->data<t>()[i])
207-
208-
template <typename Fn>
209-
inline void array::for_each_atom(Fn callback) const {
210-
if (t != T_ARR) {
211-
DO(i, n) { callback(i, array::atom_i(i)); }
212-
} else {
213-
DO_ARRAY(this, arr_t, i, e) { callback(i, e); }
214-
}
215-
}

src/words.c++

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -666,51 +666,47 @@ DEF_WORD("\\s", slash_stack) {
666666
DEF_WORD(",fold", fold) {
667667
POP(y);
668668
POP(x);
669-
t_dict_entry e = as_dict_entry(y);
670-
auto iter = [&](size_t i, array_p slice) mutable {
671-
PUSH(slice);
669+
t_dict_entry e = as_dict_entry(y);
670+
DO(i, x->n) {
671+
PUSH(x->atom_i(i));
672672
if (i > 0) inter.entry(e);
673-
};
674-
x->for_each_atom(iter);
673+
}
675674
}
676675

677676
DEF_WORD(",scan", scan) {
678677
POP(y);
679678
POP(x);
680-
t_dict_entry e = as_dict_entry(y);
681-
auto iter = [&](size_t i, array_p slice) mutable {
679+
t_dict_entry e = as_dict_entry(y);
680+
DO(i, x->n) {
682681
if (i > 0) DUP;
683-
PUSH(slice);
682+
PUSH(x->atom_i(i));
684683
if (i > 0) inter.entry(e);
685-
};
686-
x->for_each_atom(iter);
684+
}
687685
array_p result = cat(stack, x->n);
688686
PUSH(result);
689687
}
690688

691689
DEF_WORD(",apply", apply) {
692690
POP(y);
693691
POP(x);
694-
t_dict_entry e = as_dict_entry(y);
695-
auto iter = [&](size_t i, array_p slice) mutable {
696-
PUSH(slice);
692+
t_dict_entry e = as_dict_entry(y);
693+
DO(i, x->n) {
694+
PUSH(x->atom_i(i));
697695
inter.entry(e);
698696
};
699-
x->for_each_atom(iter);
700697
array_p result = cat(stack, x->n);
701698
PUSH(result);
702699
}
703700

704701
DEF_WORD(",pairwise", pairwise) {
705702
POP(y);
706703
POP(x);
707-
t_dict_entry e = as_dict_entry(y);
708-
auto iter = [&](size_t i, array_p slice) mutable {
709-
PUSH(slice);
704+
t_dict_entry e = as_dict_entry(y);
705+
DO(i, x->n) {
706+
PUSH(x->atom_i(i));
710707
if (i > 0) inter.entry(e);
711-
PUSH(slice);
708+
PUSH(x->atom_i(i));
712709
};
713-
x->for_each_atom(iter);
714710
DROP;
715711
array_p result = cat(stack, x->n);
716712
PUSH(result);

0 commit comments

Comments
 (0)