sv.c: Drop PV when assigning over regexp
authorFather Chrysostomos <sprout@cpan.org>
Mon, 29 Oct 2012 06:49:48 +0000 (23:49 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Tue, 30 Oct 2012 19:36:03 +0000 (12:36 -0700)
    $x = ${qr//};
    $x = 3;

On the second line, we don’t need to copy the stringification of the
regexp, since we are just going to clobber it anyway.

sv.c

diff --git a/sv.c b/sv.c
index 7afc266..5360b21 100644 (file)
--- a/sv.c
+++ b/sv.c
@@ -4799,8 +4799,11 @@ Perl_sv_force_normal_flags(pTHX_ register SV *const sv, const U32 flags)
        /* Remember that SvPVX is in the head, not the body. */
        assert(!SvLEN(sv));
        /* Their buffer is already owned by someone else. */
-       SvPVX(sv) = savepvn(SvPVX(sv), SvCUR(sv));
-       SvLEN_set(temp, SvCUR(sv)+1);
+       if (flags & SV_COW_DROP_PV) SvPOK_off(sv);
+       else {
+           SvPVX(sv) = savepvn(SvPVX(sv), SvCUR(sv));
+           SvLEN_set(temp, SvCUR(sv)+1);
+       }
 
        /* Now swap the rest of the bodies. */