actually, hanyv?_ptr shouldn't be a thing

This commit is contained in:
dzaima 2024-09-09 17:38:46 +03:00
parent 4cf8e10b95
commit 153850921b
3 changed files with 3 additions and 6 deletions

View File

@ -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)

View File

@ -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)));

View File

@ -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); }