From 749b098f1ee13d89b8319546b8f74502f064cbbc Mon Sep 17 00:00:00 2001 From: dzaima Date: Sat, 31 Jul 2021 22:40:33 +0300 Subject: [PATCH] use decR less --- src/builtins/arithm.c | 4 ++-- src/builtins/sfns.c | 6 +++--- src/core/stuff.c | 1 + src/h.h | 2 ++ src/ns.c | 2 +- src/vm.c | 6 +++--- 6 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/builtins/arithm.c b/src/builtins/arithm.c index 79a6ca14..6d74d414 100644 --- a/src/builtins/arithm.c +++ b/src/builtins/arithm.c @@ -54,8 +54,8 @@ B atan_c1(B t, B x) { if (isF64(x)) return m_f64( atan(x.f)); P1( atan); thrM(" #undef P1 B lt_c1(B t, B x) { return m_unit(x); } -B eq_c1(B t, B x) { B r = m_i32(isArr(x)? rnk(x) : 0); decR(x); return r; } -B ne_c1(B t, B x) { B r = m_f64(isArr(x)&&rnk(x)? *a(x)->sh : 1); decR(x); return r; } +B eq_c1(B t, B x) { B r = m_i32(isArr(x)? rnk(x) : 0); dec(x); return r; } +B ne_c1(B t, B x) { B r = m_f64(isArr(x)&&rnk(x)? *a(x)->sh : 1); dec(x); return r; } static B mathNS; diff --git a/src/builtins/sfns.c b/src/builtins/sfns.c index 2a1691a2..fd68cfb9 100644 --- a/src/builtins/sfns.c +++ b/src/builtins/sfns.c @@ -159,7 +159,7 @@ B shape_c2(B t, B w, B x) { } unit: - if (isF64(x)) { decR(xf); + if (isF64(x)) { decA(xf); i32 n = (i32)x.f; if (n == x.f) { i32* rp; Arr* r = m_i32arrp(&rp, nia); arr_shSetU(r, nr, sh); @@ -171,7 +171,7 @@ B shape_c2(B t, B w, B x) { return taga(r); } } - if (isC32(x)) { decR(xf); + if (isC32(x)) { decA(xf); u32* rp; Arr* r = m_c32arrp(&rp, nia); arr_shSetU(r, nr, sh); u32 c = o2cu(x); for (u64 i = 0; i < nia; i++) rp[i] = c; @@ -536,7 +536,7 @@ B join_c1(B t, B x) { if (xia==0) { B xf = getFillE(x); if (isAtm(xf)) { - decR(xf); + decA(xf); if (!PROPER_FILLS) { B xfq = getFillR(x); bool no = noFill(xfq); diff --git a/src/core/stuff.c b/src/core/stuff.c index 2e041b88..404ae182 100644 --- a/src/core/stuff.c +++ b/src/core/stuff.c @@ -24,6 +24,7 @@ NOINLINE B c2_rare(B f, B w, B x) { dec(w); dec(x); return inc(VALIDATE(f)); } NOINLINE void value_freeR(Value* x) { value_free(x); } +NOINLINE void decA_rare(B x) { dec(x); } void noop_visit(Value* x) { } NOINLINE B c1_invalid(B f, B x) { thrM("This function can't be called monadically"); } NOINLINE B c2_invalid(B f, B w, B x) { thrM("This function can't be called dyadically"); } diff --git a/src/h.h b/src/h.h index c2f76860..d3f69b56 100644 --- a/src/h.h +++ b/src/h.h @@ -421,6 +421,8 @@ static void decR(B x) { Value* vx = v(x); if(!--vx->refc) value_freeR(vx); } +void decA_rare(B x); +static void decA(B x) { if (RARE(isVal(x))) decA_rare(x); } // decrement what's likely an atom static B inc(B x) { if (isVal(VALIDATE(x))) v(x)->refc++; return x; diff --git a/src/ns.c b/src/ns.c index dc9dcc7c..e0031b29 100644 --- a/src/ns.c +++ b/src/ns.c @@ -107,7 +107,7 @@ B ns_nameList(NSDesc* d) { DEF_FREE(ns) { NS* c = (NS*)x; ptr_decR(c->desc); - ptr_decR(c->sc); + ptr_dec(c->sc); } static void ns_visit(Value* x) { NS* c = (NS*)x; diff --git a/src/vm.c b/src/vm.c index 034f1011..2d0c212f 100644 --- a/src/vm.c +++ b/src/vm.c @@ -805,9 +805,9 @@ DEF_FREE(block) { for (i32 i = 0; i < am; i++) ptr_decR(c->bodies[i]); } DEF_FREE(comp) { Comp* c = (Comp *)x; ptr_decR(c->objs); decR(c->bc); decR(c->src); decR(c->indices); decR(c->path); } -DEF_FREE(funBl) { FunBlock* c = (FunBlock*)x; ptr_decR(c->sc); ptr_decR(c->bl); } -DEF_FREE(md1Bl) { Md1Block* c = (Md1Block*)x; ptr_decR(c->sc); ptr_decR(c->bl); } -DEF_FREE(md2Bl) { Md2Block* c = (Md2Block*)x; ptr_decR(c->sc); ptr_decR(c->bl); } +DEF_FREE(funBl) { FunBlock* c = (FunBlock*)x; ptr_dec(c->sc); ptr_decR(c->bl); } +DEF_FREE(md1Bl) { Md1Block* c = (Md1Block*)x; ptr_dec(c->sc); ptr_decR(c->bl); } +DEF_FREE(md2Bl) { Md2Block* c = (Md2Block*)x; ptr_dec(c->sc); ptr_decR(c->bl); } DEF_FREE(alias) { dec(((FldAlias*)x)->obj); } DEF_FREE(bBlks) { BlBlocks* c = (BlBlocks*)x; u16 am = c->am; for (i32 i = 0; i < am; i++) ptr_dec(c->a[i]); } DEF_FREE(scExt) { ScopeExt* c = (ScopeExt*)x; u16 am = c->varAm*2; for (i32 i = 0; i < am; i++) dec(c->vars[i]); }