From 4884580037edb24612e69dd7a6081f2d1cc6c13e Mon Sep 17 00:00:00 2001 From: dzaima Date: Wed, 28 Dec 2022 16:23:27 +0200 Subject: [PATCH] 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 --- src/core/stuff.h | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/core/stuff.h b/src/core/stuff.h index 597ad8e5..8b543809 100644 --- a/src/core/stuff.h +++ b/src/core/stuff.h @@ -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; }