diff --git a/src/utils/mut.c b/src/utils/mut.c index 8db2b756..7e66146e 100644 --- a/src/utils/mut.c +++ b/src/utils/mut.c @@ -393,6 +393,8 @@ static B m_getU_c32(Mut* m, usz ms) { return m_c32(m->ac32[ms]); } static B m_getU_f64(Mut* m, usz ms) { return m_f64(m->af64[ms]); } static B m_getU_B (Mut* m, usz ms) { return m->aB[ms]; } +M_CopyF copyFns[el_MAX]; + MutFns mutFns[el_MAX+1]; u8 el_orArr[el_MAX*16 + el_MAX+1]; void mutF_init() { @@ -422,4 +424,5 @@ void mutF_init() { mutFns[el_f64].elType = el_f64; mutFns[el_f64].valType = t_f64arr; mutFns[el_B ].elType = el_B ; mutFns[el_B ].valType = t_harr; mutFns[el_MAX].elType = el_MAX; mutFns[el_MAX].valType = t_COUNT; + for (u8 i = 0; i < el_MAX; i++) copyFns[i] = mutFns[i].m_copyG; } diff --git a/src/utils/mut.h b/src/utils/mut.h index ef8fbfcf..85f07f78 100644 --- a/src/utils/mut.h +++ b/src/utils/mut.h @@ -158,48 +158,34 @@ static void bit_cpy(u64* r, usz rs, u64* x, usz xs, usz l) { B vec_join(B w, B x); // consumes both + +extern M_CopyF copyFns[el_MAX]; +#define COPY_TO(WHERE, ELT, MS, X, XS, LEN) copyFns[ELT](WHERE, MS, X, XS, LEN) + // if `consume==true`, consumes w,x and expects both args to be vectors // else, doesn't consume x, and decrements refcount of w iif *reusedW (won't free because the result will be w) FORCE_INLINE B arr_join_inline(B w, B x, bool consume, bool* reusedW) { usz wia = IA(w); usz xia = IA(x); - usz ria = wia+xia; - if (reusable(w)) { - u64 wsz = mm_size(v(w)); - u8 wt = TY(w); - // TODO f64∾i32, i32∾i8, c32∾c8 etc - switch (wt) { - case t_bitarr: if (BITARR_SZ( ria)=el_c8) goto yes; break; + case t_c32arr: if (TYARR_SZ(C32,ria)=el_c8) goto yes; break; + case t_harr: if (fsizeof(HArr,a,B,ria)ia = ria; - return FL_KEEP(w,fl_squoze); // keeping fl_squoze as appending items can't make the smallest item smaller + return FL_KEEP(w,fl_squoze); // keeping fl_squoze as appending items can't make the largest item smaller } static inline bool inplace_add(B w, B x) { // consumes x if returns true; fails if fills wouldn't be correct