This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
m// and s///; don't copy TEMP/AMAGIC strings
authorDavid Mitchell <davem@iabyn.com>
Sat, 1 Sep 2012 10:43:53 +0000 (11:43 +0100)
committerDavid Mitchell <davem@iabyn.com>
Sat, 8 Sep 2012 14:42:07 +0000 (15:42 +0100)
Currently pp_match and pp_subst make a copy of the match string if it's
SvTEMP(), and in the case of pp_match, also if it's SvAMAGIC().

This is no longer necessary, as the code will always copy the string
anyway if its actually needed after the match, i.e. if it detects the
presence of $1, $& or //p etc. Until a few commits ago, this wasn't the
case for pp_match: it would sometimes skip copying even in the presence of
$1 et al for efficiency reasons. Now that that's fixed, we can remove the
SvTEMP() and SvAMAGIC() tests.

As to why pp_subst did the SvTEMP test, I don't know: but removing it
didn't make any tests fail!

pp_hot.c

index b549d1c..0d70dfc 100644 (file)
--- a/pp_hot.c
+++ b/pp_hot.c
@@ -1321,8 +1321,6 @@ PP(pp_match)
     }
     if (       RX_NPARENS(rx)
             || PL_sawampersand
-            || SvTEMP(TARG)
-            || SvAMAGIC(TARG)
             || (RX_EXTFLAGS(rx) & (RXf_EVAL_SEEN|RXf_PMf_KEEPCOPY))
     ) {
        r_flags |= (REXEC_COPY_STR|REXEC_COPY_SKIP_PRE);
@@ -2139,7 +2137,6 @@ PP(pp_subst)
 
     r_flags = (    RX_NPARENS(rx)
                 || PL_sawampersand
-                || SvTEMP(TARG)
                 || (RX_EXTFLAGS(rx) & (RXf_EVAL_SEEN|RXf_PMf_KEEPCOPY))
               )
           ? REXEC_COPY_STR