From cd97714ef59467f88b088dcb688a3a788426fb92 Mon Sep 17 00:00:00 2001 From: dzaima Date: Sat, 20 Nov 2021 17:09:05 +0200 Subject: [PATCH] ptr_dec with inlined freeing method --- src/core/stuff.h | 2 +- src/h.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/core/stuff.h b/src/core/stuff.h index ef6bc73f..3ebc39df 100644 --- a/src/core/stuff.h +++ b/src/core/stuff.h @@ -19,7 +19,7 @@ typedef struct ShArr { static ShArr* shObjS(usz* x) { return RFLD(x, ShArr, a); } static ShArr* shObj (B x) { return RFLD(a(x)->sh, ShArr, a); } static ShArr* shObjP(Value* x) { return RFLD(((Arr*)x)->sh, ShArr, a); } -static void decSh(Value* x) { if (RARE(prnk(x)>1)) ptr_dec(shObjP(x));} +static void decSh(Value* x) { if (RARE(prnk(x)>1)) tptr_dec(shObjP(x), mm_free); } // some array stuff diff --git a/src/h.h b/src/h.h index 1a6e7f28..05321ecc 100644 --- a/src/h.h +++ b/src/h.h @@ -498,6 +498,7 @@ static void dec(B x) { } static void ptr_dec(void* x) { if(!--VALIDATEP((Value*)x)->refc) value_free(x); } static void ptr_decR(void* x) { if(!--VALIDATEP((Value*)x)->refc) value_freeR(x); } +#define tptr_dec(X, F) ({ Value* x_ = (Value*)(X); if (!--VALIDATEP(x_)->refc) F(x_); }) static void decR(B x) { if (!isVal(VALIDATE(x))) return; Value* vx = v(x);