From eca92b6a5db1e24752e716d4f308870c7c925653 Mon Sep 17 00:00:00 2001 From: dzaima Date: Fri, 28 Jan 2022 04:07:29 +0200 Subject: [PATCH] reorder scope_dec --- src/vm.h | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/vm.h b/src/vm.h index 2b3932fd..44ea77bf 100644 --- a/src/vm.h +++ b/src/vm.h @@ -242,24 +242,24 @@ DEF_FREE(scope) { } FORCE_INLINE void scope_dec(Scope* sc) { // version of ptr_dec for scopes, that tries to also free trivial cycles. force-inlined!! i32 varAm = sc->varAm; - if (sc->refc>1) { - i32 innerRef = 1; - for (i32 i = 0; i < varAm; i++) { - B c = sc->vars[i]; - if (isVal(c) && v(c)->refc==1) { - u8 t = v(c)->type; - if (t==t_funBl && c(FunBlock,c)->sc==sc) innerRef++; - else if (t==t_md1Bl && c(Md1Block,c)->sc==sc) innerRef++; - else if (t==t_md2Bl && c(Md2Block,c)->sc==sc) innerRef++; - } - } - assert(innerRef <= sc->refc); - if (innerRef==sc->refc) { - value_free((Value*)sc); - return; + if (LIKELY(sc->refc==1)) goto free; + i32 innerRef = 1; + for (i32 i = 0; i < varAm; i++) { + B c = sc->vars[i]; + if (isVal(c) && v(c)->refc==1) { + u8 t = v(c)->type; + if (t==t_funBl && c(FunBlock,c)->sc==sc) innerRef++; + else if (t==t_md1Bl && c(Md1Block,c)->sc==sc) innerRef++; + else if (t==t_md2Bl && c(Md2Block,c)->sc==sc) innerRef++; } } - tptr_dec(sc, scope_freeF); + assert(innerRef <= sc->refc); + if (innerRef==sc->refc) goto free; + sc->refc--; // refc>0 guaranteed by previous refc!=1 result + return; + + free: + scope_freeF((Value*) sc); }