rearrange arr_shCopyUnchecked to not read SH(o) twice

and, while making a change that requires rebuilding all of CBQN, also make more of the arr_* fns return their Arr* argument to prepare for using them inline
This commit is contained in:
dzaima 2022-12-28 16:23:27 +02:00
parent 3b1b171828
commit 4884580037

View File

@ -63,23 +63,26 @@ static usz* arr_shAlloc(Arr* x, ur r) { // sets rank, allocates & returns shape
x->sh = &x->ia;
return NULL;
}
static void arr_shSetI(Arr* x, ur r, ShArr* sh) { // set rank and assign and increment shape if needed
static Arr* arr_shSetI(Arr* x, ur r, ShArr* sh) { // set rank and assign and increment shape if needed
SPRNK(x,r);
if (r>1) { x->sh = ptr_inc(sh)->a; }
else { x->sh = &x->ia; }
if (r>1) x->sh = ptr_inc(sh)->a;
else x->sh = &x->ia;
return x;
}
static void arr_shSetU(Arr* x, ur r, ShArr* sh) { // set rank and assign shape
static Arr* arr_shSetU(Arr* x, ur r, ShArr* sh) { // set rank and assign shape
SPRNK(x,r);
if (r>1) { x->sh = sh->a; }
else { x->sh = &x->ia; }
if (r>1) x->sh = sh->a;
else x->sh = &x->ia;
return x;
}
static Arr* arr_shCopyUnchecked(Arr* n, B o) {
ur r = SPRNK(n,RNK(o));
if (r<=1) {
n->sh = &n->ia;
} else {
ptr_inc(shObj(o));
n->sh = SH(o);
usz* sh = SH(o);
ptr_inc(shObjS(sh));
n->sh = sh;
}
return n;
}