arr_shCopy that doesn't compare IA

This commit is contained in:
dzaima 2022-11-15 17:58:57 +02:00
parent 179e0a37dc
commit 1ac5f0a49d
2 changed files with 9 additions and 5 deletions

View File

@ -1231,7 +1231,7 @@ B bitop1(B f, B x, enum BitOp1 op, char* name) {
B r; u64* rp;
if (v(x)->refc!=1 || (rt==t_bitarr && IS_SLICE(TY(x)))) {
Arr* ra = m_arr(offsetof(TyArr,a) + (n+7)/8, rt, n>>rws);
arr_shCopy(ra, x);
arr_shCopyUnchecked(ra, x);
r = taga(ra); rp = tyany_ptr(r);
} else {
r = inc(x); rp = xp;
@ -1304,7 +1304,7 @@ B bitop2(B f, B w, B x, enum BitOp2 op, char* name) {
x = convert((CastType){ xw, isCharType(TY(x)) }, x);
u8 rt = typeOfCast((CastType){ rw, 0 });
Arr* ra = m_arr(offsetof(TyArr,a) + (n+7)/8, rt, n>>rws);
arr_shCopy(ra, x);
arr_shCopyUnchecked(ra, x);
B r = taga(ra);
u64* wp = tyany_ptr(w);
u64* xp = tyany_ptr(x);

View File

@ -73,9 +73,7 @@ static void arr_shSetU(Arr* x, ur r, ShArr* sh) { // set rank and assign shape
if (r>1) { x->sh = sh->a; }
else { x->sh = &x->ia; }
}
static void arr_shCopy(Arr* n, B o) { // copy shape & rank from o to n
assert(isArr(o));
assert(IA(o)==n->ia);
static Arr* arr_shCopyUnchecked(Arr* n, B o) {
ur r = SPRNK(n,RNK(o));
if (r<=1) {
n->sh = &n->ia;
@ -83,6 +81,12 @@ static void arr_shCopy(Arr* n, B o) { // copy shape & rank from o to n
ptr_inc(shObj(o));
n->sh = SH(o);
}
return n;
}
static Arr* arr_shCopy(Arr* n, B o) { // copy shape & rank from o to n
assert(isArr(o));
assert(IA(o)==n->ia);
return arr_shCopyUnchecked(n, o);
}
static void shcpy(usz* dst, usz* src, size_t len) {
// memcpy(dst, src, len*sizeof(usz));