This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
clear_defarray(): clear @_ if possible
[perl5.git] / pp_hot.c
index c2ee827..f719b40 100644 (file)
--- a/pp_hot.c
+++ b/pp_hot.c
@@ -3340,11 +3340,15 @@ Perl_clear_defarray(pTHX_ AV* av, bool abandon)
 
     PERL_ARGS_ASSERT_CLEAR_DEFARRAY;
 
 
     PERL_ARGS_ASSERT_CLEAR_DEFARRAY;
 
-    SvREFCNT_dec_NN(av);
-    av = newAV();
-    av_extend(av, fill);
+    if (LIKELY(!abandon && SvREFCNT(av) == 1 && !SvMAGICAL(av)))
+        av_clear(av);
+    else {
+        SvREFCNT_dec_NN(av);
+        av = newAV();
+        PAD_SVl(0) = MUTABLE_SV(av);
+        av_extend(av, fill);
+    }
     AvREIFY_only(av);
     AvREIFY_only(av);
-    PAD_SVl(0) = MUTABLE_SV(av);
 }
 
 
 }