diff --git a/src/builtins/select.c b/src/builtins/select.c index 6a32fdb4..16ba3ca5 100644 --- a/src/builtins/select.c +++ b/src/builtins/select.c @@ -598,18 +598,30 @@ B select_replace(u32 chr, B w, B x, B rep, usz wia, usz cam, usz csz) { // consu #undef FREE_CHECK } -static void* m_arrv_same_t(B* r, usz ia, u8 ty) { +static void* m_arrv_same_t(B* r, B** rbp, usz ia, u8 ty, B src) { + assert(isArr(src)); u8 se = TIi(ty,elType); if (se==el_B) { - HArr_p p = m_harr0v(ia); - *r = p.b; - return p.a; + B fill = getFillQ(src); + if (noFill(fill)) { + HArr_p p = m_harrUv(ia); + *rbp = p.a; + *r = p.b; + } else { + Arr* ra = m_fillarrp(ia); + fillarr_setFill(ra, fill); + *rbp = fillarrv_ptr(ra); + *r = taga(ra); + } + FILL_TO(*rbp, el_B, 0, m_f64(0), ia); + NOGC_E; + return *rbp; } else { return m_tyarrlbv(r, arrTypeBitsLog(ty), ia, arrNewType(ty)); } } -static void* m_arrv_same(B* r, usz ia, B src) { // makes a new array with same element type as src, but new ia - return m_arrv_same_t(r, ia, TY(src)); +static void* m_arrv_same(B* r, B** rbp, usz ia, B src) { // makes a new array with same element type and fill as src, but new ia + return m_arrv_same_t(r, rbp, ia, TY(src), src); } B slash_c2(B, B, B); @@ -696,6 +708,7 @@ B select_rows_direct(B x, ux csz, ux cam, void* inds, ux indn, u8 ie) { // ⥊ ( ux ria = indn * cam; B r; + B* rbp = NULL; u8* xp; u8 xe = TI(x,elType); u8 lb = arrTypeWidthLog(TY(x)); @@ -723,13 +736,13 @@ B select_rows_direct(B x, ux csz, ux cam, void* inds, ux indn, u8 ie) { // ⥊ ( if (ie==el_bit) { // TODO path for xe==el_bit + long indn if (HEURISTIC_BOUNDED(csz>32 || indn>32 || indn>INDS_BUF_MAX, xe!=el_bit && (csz>8 || indn>8), true)) { // TODO properly tune - u8* rp = m_arrv_same(&r, ria, x); + u8* rp = m_arrv_same(&r, &rbp, ria, x); for (ux i = 0; i < cam; i++) { bitselFns[lb](rp, inds, loadu_u64(xp), loadu_u64(xp + (1<