From 056cfd836731c716beed4dd50d5fd49e8d933fff Mon Sep 17 00:00:00 2001 From: dzaima Date: Thu, 29 May 2025 23:22:46 +0300 Subject: [PATCH] extract m_barrp_fill, make m_arrp_fill actually set fill conditions were the wrong way around :| --- src/utils/mut.c | 24 +++++++++++++----------- src/utils/mut.h | 3 ++- test/cases/prims.bqn | 1 + 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/utils/mut.c b/src/utils/mut.c index a459dc08..ff440b17 100644 --- a/src/utils/mut.c +++ b/src/utils/mut.c @@ -832,19 +832,21 @@ DirectArr toEltypeArr(B x, u8 re) { // consumes +UntaggedArr m_barrp_fill(B x, ux ia) { // doesn't consume + B fill = getFillR(x); + if (noFill(fill)) { + HArr_p r = m_harrUp(ia); + return (UntaggedArr) {(Arr*)r.c, r.a}; + } else { + Arr* r = m_fillarrp(ia); + fillarr_setFill(r, fill); + return (UntaggedArr){r, fillarrv_ptr(r)}; + } +} + UntaggedArr m_arrp_fill(B x, ux ia) { // doesn't consume u8 xe = TI(x,elType); - if (xe==el_B) { - B fill = getFillR(x); - if (noFill(fill)) { - Arr* r = m_fillarrp(ia); - fillarr_setFill(r, fill); - return (UntaggedArr){r, fillarrv_ptr(r)}; - } else { - HArr_p r = m_harrUp(ia); - return (UntaggedArr) {(Arr*)r.c, r.a}; - } - } + if (xe==el_B) return m_barrp_fill(x, ia); Arr* r; void* rp = m_tyarrlbp(&r, elwBitLog(xe), ia, el2t(xe)); return (UntaggedArr) {r, rp}; diff --git a/src/utils/mut.h b/src/utils/mut.h index 7ff4b7da..0bc5663a 100644 --- a/src/utils/mut.h +++ b/src/utils/mut.h @@ -298,7 +298,8 @@ DirectArr toEltypeArr(B x, u8 re); // consumes DirectArr potentiallyReuse(B x); // doesn't consume typedef struct { Arr* obj; void* data; } UntaggedArr; -UntaggedArr m_arrp_fill(B x, ux ia); // doesn't consume; create new array with the fill and eltype of x +UntaggedArr m_barrp_fill(B x, ux ia); // doesn't consume; create new fillarr or harr with the fill of x +UntaggedArr m_arrp_fill(B x, ux ia); // doesn't consume; create new array with the fill and eltype of x typedef struct { B res; diff --git a/test/cases/prims.bqn b/test/cases/prims.bqn index 39d3adbe..0da2ccaa 100644 --- a/test/cases/prims.bqn +++ b/test/cases/prims.bqn @@ -410,6 +410,7 @@ b←1↓1∾a←"hello" ⋄ b ⌽⎊'e' ⥊⟜1⍟2 5 ⋄ a ≡○•Hash b %% 1 %USE eqvarv ⋄ ↑‿4 ⥊_eqvarv_"i" "abcde" %% ["abcd", "e "] %USE eqvar ⋄ ⌽‿4 ⥊_eqvar "abcde" %% ["abcd", "eabc"] %USE eqvar ⋄ ⌊‿4 ⥊_eqvar "abcde" %% ["abcd"] +%USE eqvar ⋄ 2‿2 ⥊_eqvar ↕1000 %% [0‿1,2‿3] # 𝕨⍷𝕩 %USE eqvar ⋄ "ab" ⍷_eqvar "" %% ⟨⟩