From c70a25495e335e9b4c9d18536444a9fae0266525 Mon Sep 17 00:00:00 2001 From: Father Chrysostomos Date: Mon, 21 Nov 2011 08:40:34 -0800 Subject: [PATCH] =?utf8?q?Don=E2=80=99t=20call=20an=20early-returning=20de?= =?utf8?q?structor?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This speeds things up 2.8 times in my naïve benchmarks. This applies to code like: use constant DEBUG => 1; DESTROY { return unless DEBUG; ... } which gets optimised down to: DESTROY { return; ... } Adding such a destructor will now have almost no impact on speed in production. --- sv.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/sv.c b/sv.c index ba656a9..0095e07 100644 --- a/sv.c +++ b/sv.c @@ -6303,11 +6303,19 @@ S_curse(pTHX_ SV * const sv, const bool check_refcnt) { /* A constant subroutine can have no side effects, so don't bother calling it. */ && !CvCONST(destructor) - /* Don't bother calling an empty destructor */ + /* Don't bother calling an empty destructor or one that + returns immediately. */ && (CvISXSUB(destructor) || (CvSTART(destructor) && (CvSTART(destructor)->op_next->op_type - != OP_LEAVESUB)))) + != OP_LEAVESUB) + && (CvSTART(destructor)->op_next->op_type + != OP_PUSHMARK + || CvSTART(destructor)->op_next->op_next->op_type + != OP_RETURN + ) + )) + ) { SV* const tmpref = newRV(sv); SvREADONLY_on(tmpref); /* DESTROY() could be naughty */ -- 2.7.4