From 153850921b5d0d9deec277f63bdb24951dcfeae3 Mon Sep 17 00:00:00 2001 From: dzaima Date: Mon, 9 Sep 2024 17:38:46 +0300 Subject: [PATCH] actually, hanyv?_ptr shouldn't be a thing --- src/README.md | 5 ++--- src/builtins/internal.c | 2 +- src/core/harr.h | 2 -- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/README.md b/src/README.md index 4d845010..779a896d 100644 --- a/src/README.md +++ b/src/README.md @@ -327,10 +327,9 @@ B c = IGetU(x,n); // for specific array types: if (TI(x,elType)==el_i32) i32* xp = i32any_ptr(x); // for either t_i32arr or t_i32slice; for t_i32arr only, there's i32arr_ptr(x); same for all other primitive element types (bitarr has bitany_ptr but no slice type yet) if (TI(x,elType)!=el_B) void* xp = tyany_ptr(x); // alternative equivalent check: IS_ANY_ARR(TY(x)); tyarr_ptr if the input is also known to not be a slice -if (TY(x)==t_harr) B* xp = harr_ptr(x); -if (TY(x)==t_harr || TY(x)==t_hslice) B* xp = hany_ptr(x); // note that elType==el_B doesn't imply hany_ptr is safe! -if (TY(x)==t_fillarr) B* xp = fillarr_ptr(x); +if (TY(x)==t_harr) B* xp = harr_ptr(x); // similarly, hslice_ptr, fillarrv_ptr, fillslicev_ptr for specific types B* xp = arr_bptr(x); // will return NULL if the array isn't backed by a contiguous B* +// while currently there are no types with eltype el_B for which arr_bptr isn't NULL, that could change in the future and so should still be handled // functions to convert arrays to a specific type array: (all consume their argument, and assume that the elements losslessly fit in the desired type) I8Arr* a = toI8Arr(x); // convert x to an I8Arr instance (returns the argument if it already is) diff --git a/src/builtins/internal.c b/src/builtins/internal.c index 58d84daf..ac98f98f 100644 --- a/src/builtins/internal.c +++ b/src/builtins/internal.c @@ -244,7 +244,7 @@ static B unshare(B x) { case t_c32arr: case t_c32slice: return unshareShape((Arr*)cpyC32Arr(incG(x))); case t_f64arr: case t_f64slice: return unshareShape((Arr*)cpyF64Arr(incG(x))); case t_harr: case t_hslice: { - B* xp = hany_ptr(x); + B* xp = TY(x)==t_harr? harr_ptr(x) : hslice_ptr(x); M_HARR(r, xia) for (usz i = 0; i < xia; i++) HARR_ADD(r, i, unshare(xp[i])); return unshareShape(a(HARR_FC(r, x))); diff --git a/src/core/harr.h b/src/core/harr.h index 3d48faf9..3ded9f0c 100644 --- a/src/core/harr.h +++ b/src/core/harr.h @@ -110,10 +110,8 @@ static B m_hunit(B x) { // consumes static B* harrv_ptr(void* x) { u8 t = PTY((Value*)x); assert(t==t_harr || t==t_harrPartial); return ((HArr*)x)->a; } static B* hslicev_ptr(void* x) { VTY(taga(x),t_hslice); return ((HSlice*)x)->a; } -static B* hanyv_ptr(void* x) { return PTY((Value*)x)==t_hslice? hslicev_ptr(x) : harrv_ptr(x); } static B* harr_ptr(B x) { return harrv_ptr(a(x)); } static B* hslice_ptr(B x) { return hslicev_ptr(a(x)); } -static B* hany_ptr(B x) { return hanyv_ptr(a(x)); } Arr* cpyHArr(B x); // consumes static HArr* toHArr(B x) { return TY(x)==t_harr? c(HArr,x) : (HArr*) cpyHArr(x); }