This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Stop calling get-magic twice when reading lvalue substr($utf8)
authorFather Chrysostomos <sprout@cpan.org>
Fri, 31 Aug 2012 05:34:38 +0000 (22:34 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Fri, 31 Aug 2012 05:34:38 +0000 (22:34 -0700)
mg.c
t/op/tie_fetch_count.t

diff --git a/mg.c b/mg.c
index 2de58e4..3dea5c2 100644 (file)
--- a/mg.c
+++ b/mg.c
@@ -2241,7 +2241,7 @@ Perl_magic_setsubstr(pTHX_ SV *sv, MAGIC *mg)
        Perl_ck_warner(aTHX_ packWARN(WARN_SUBSTR),
                            "Attempt to use reference as lvalue in substr"
        );
-    if (SvUTF8(lsv)) lsv_len = sv_len_utf8(lsv);
+    if (SvUTF8(lsv)) lsv_len = sv_len_utf8_nomg(lsv);
     else (void)SvPV_nomg(lsv,lsv_len);
     if (!translate_substr_offsets(
            lsv_len,
index dfed65e..48a070b 100644 (file)
@@ -7,7 +7,7 @@ BEGIN {
     chdir 't' if -d 't';
     @INC = '../lib';
     require './test.pl';
-    plan (tests => 306);
+    plan (tests => 307);
 }
 
 use strict;
@@ -253,6 +253,7 @@ pos$var = 0             ; check_count 'lvalue pos $utf8';
 $dummy  = substr$var,0,1; check_count 'substr $utf8';
 my $l   =\substr$var,0,1;
 $dummy  = $$l           ; check_count 'reading lvalue substr($utf8)';
+$$l     = 0             ; check_count 'setting lvalue substr($utf8)';
 
 {
     local $SIG{__WARN__} = sub {};