From: Yitzchak Scott-Thoennes Date: Tue, 4 Mar 2008 16:54:29 +0000 (-0800) Subject: count-only transliteration needlessly makes copy-on-write X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=3788ef8ffa548a64c7425dab843bc6e906dec25c;p=p5sagit%2Fp5-mst-13.2.git count-only transliteration needlessly makes copy-on-write From: "Yitzchak Scott-Thoennes" Message-ID: <47935.71.32.86.11.1204678469.squirrel@webmail.efn.org> p4raw-id: //depot/perl@33457 --- diff --git a/doop.c b/doop.c index 1a5c829..8bd7c0f 100644 --- a/doop.c +++ b/doop.c @@ -633,10 +633,10 @@ Perl_do_trans(pTHX_ SV *sv) PERL_ARGS_ASSERT_DO_TRANS; - if (SvREADONLY(sv)) { + if (SvREADONLY(sv) && !(PL_op->op_private & OPpTRANS_IDENTICAL)) { if (SvIsCOW(sv)) sv_force_normal_flags(sv, 0); - if (SvREADONLY(sv) && !(PL_op->op_private & OPpTRANS_IDENTICAL)) + if (SvREADONLY(sv)) Perl_croak(aTHX_ PL_no_modify); } (void)SvPV_const(sv, len); diff --git a/t/op/tr.t b/t/op/tr.t index 279470c..9273e09 100755 --- a/t/op/tr.t +++ b/t/op/tr.t @@ -6,7 +6,7 @@ BEGIN { require './test.pl'; } -plan tests => 117; +plan tests => 118; my $Is_EBCDIC = (ord('i') == 0x89 & ord('J') == 0xd1); @@ -461,3 +461,10 @@ is($s, "AxBC", "utf8, DELETE"); is($c, "\x20\x30\x40\x50\x60", "tr/\\x00-\\x1f//d"); } +($s) = keys %{{pie => 3}}; +my $wasro = Internals::SvREADONLY($s); +{ + $wasro or local $TODO = "didn't have a COW"; + $s =~ tr/i//; + ok( Internals::SvREADONLY($s), "count-only tr doesn't deCOW COWs" ); +}