slightly less wrong superset fills for 𝕨∾𝕩

This commit is contained in:
dzaima 2023-05-20 14:28:28 +03:00
parent d6609df820
commit d15d8febbe
2 changed files with 8 additions and 8 deletions

View File

@ -99,11 +99,10 @@ B vec_join(B w, B x) {
}
NOINLINE JoinFillslice fillslice_getJoin(B w, B x, usz ria) {
NOINLINE JoinFillslice fillslice_getJoin(B w, usz ria) {
usz wia = IA(w);
assert(TY(w)==t_fillslice);
FillSlice* s = c(FillSlice,w);
if (!fillEqualsGetFill(s->fill, x)) goto no;
Arr* p = s->p;
if (p->refc!=1) goto no;
@ -113,6 +112,7 @@ NOINLINE JoinFillslice fillslice_getJoin(B w, B x, usz ria) {
if (PIA(p)!=wia) goto no;
usz wsz = mm_sizeUsable((Value*)p);
if (!(p->type==t_fillarr? fsizeof(FillArr,a,B,ria)<wsz : fsizeof(HArr,a,B,ria)<wsz)) goto no;
if (p->type==t_fillarr) { B* f = &((FillArr*)p)->fill; dec(*f); *f = bi_noFill; }
ur sr = PRNK(s);
if (sr<=1) {
@ -121,7 +121,6 @@ NOINLINE JoinFillslice fillslice_getJoin(B w, B x, usz ria) {
usz* ssh = PSH(s);
if (ssh != PSH(p)) arr_shReplace(p, sr, ptr_inc(shObjS(ssh)));
}
B w2 = taga(ptr_inc(p));
value_free((Value*)s);
return (JoinFillslice){w2, rp};

View File

@ -153,10 +153,11 @@ SHOULD_INLINE void bit_cpy(u64* r, usz rs, u64* x, usz xs, usz l) {
typedef struct { B w2; void* rp; } JoinFillslice;
JoinFillslice fillslice_getJoin(B w, B x, usz ria); // either returns NULL in rp, or consumes w
JoinFillslice fillslice_getJoin(B w, usz ria); // either returns NULL in rp, or consumes w
// if `consume==true`, consumes w,x and expects both args to be vectors
// else, doesn't consume x, and decrements refcount of w iif *reusedW (won't free because the result will be w)
// consume==true: consumes w,x and expects both args to be vectors
// consume==false: doesn't consume x, and decrements refcount of w iif *reusedW (won't free because the result will be w); result has arbitrary but valid shape
// returns possibly incorrect fills if arguments aren't equal class typed arrays
FORCE_INLINE B arr_join_inline(B w, B x, bool consume, bool* reusedW) {
assert(isArr(w) && isArr(x));
usz wia = IA(w);
@ -177,13 +178,13 @@ FORCE_INLINE B arr_join_inline(B w, B x, bool consume, bool* reusedW) {
case t_c16arr: if (TYARR_SZ(C16,ria)<wsz && TI(x,elType)<=el_c16 && TI(x,elType)>=el_c8) goto yes; break;
case t_c32arr: if (TYARR_SZ(C32,ria)<wsz && TI(x,elType)<=el_c32 && TI(x,elType)>=el_c8) goto yes; break;
case t_fillslice: {
JoinFillslice t = fillslice_getJoin(w, x, ria);
JoinFillslice t = fillslice_getJoin(w, ria);
if (t.rp==NULL) goto no;
w = t.w2;
rp = t.rp;
goto yes;
}
case t_fillarr: if (fsizeof(FillArr,a,B,ria)<wsz) { rp = fillarr_ptr(a(w)); if (fillEqualsGetFill(c(FillArr,x)->fill, x)) goto yes; } break;
case t_fillarr: if (fsizeof(FillArr,a,B,ria)<wsz) { rp = fillarr_ptr(a(w)); dec(c(FillArr,w)->fill); c(FillArr,w)->fill = bi_noFill; goto yes; } break;
case t_harr: if (fsizeof(HArr, a,B,ria)<wsz) { rp = harr_ptr( w ); goto yes; } break;
}
no:; // failed to reuse