Optimize away calls to empty DESTROY methods
Rafael Garcia-Suarez [Tue, 20 Jan 2009 08:11:18 +0000 (09:11 +0100)]
sv.c

diff --git a/sv.c b/sv.c
index d944e2f..ae728b1 100644 (file)
--- a/sv.c
+++ b/sv.c
@@ -5655,7 +5655,11 @@ Perl_sv_clear(pTHX_ register SV *const sv)
                CV* destructor;
                stash = SvSTASH(sv);
                destructor = StashHANDLER(stash,DESTROY);
-               if (destructor) {
+               if (destructor
+                       /* Don't bother calling an empty destructor */
+                       && (CvISXSUB(destructor)
+                       || CvSTART(destructor)->op_next->op_type != OP_LEAVESUB))
+               {
                    SV* const tmpref = newRV(sv);
                    SvREADONLY_on(tmpref);   /* DESTROY() could be naughty */
                    ENTER;