Stop calling get-magic twice in sprintf "%.1s", $utf8
authorFather Chrysostomos <sprout@cpan.org>
Fri, 31 Aug 2012 06:27:43 +0000 (23:27 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Fri, 31 Aug 2012 06:27:43 +0000 (23:27 -0700)
sv.c
t/op/tie_fetch_count.t

diff --git a/sv.c b/sv.c
index fa0fb23..497417c 100644 (file)
--- a/sv.c
+++ b/sv.c
@@ -10517,10 +10517,10 @@ Perl_sv_vcatpvfn_flags(pTHX_ SV *const sv, const char *const pat, const STRLEN p
                if (DO_UTF8(argsv)) {
                    STRLEN old_precis = precis;
                    if (has_precis && precis < elen) {
-                       STRLEN ulen = sv_len_utf8(argsv);
-                       I32 p = precis > ulen ? ulen : precis;
-                       sv_pos_u2b(argsv, &p, 0); /* sticks at end */
-                       precis = p;
+                       STRLEN ulen = sv_len_utf8_nomg(argsv);
+                       STRLEN p = precis > ulen ? ulen : precis;
+                       precis = sv_pos_u2b_flags(argsv, p, 0, 0);
+                                                       /* sticks at end */
                    }
                    if (width) { /* fudge width (can't fudge elen) */
                        if (has_precis && precis < elen)
index 50671d9..48cc914 100644 (file)
@@ -7,7 +7,7 @@ BEGIN {
     chdir 't' if -d 't';
     @INC = '../lib';
     require './test.pl';
-    plan (tests => 309);
+    plan (tests => 310);
 }
 
 use strict;
@@ -255,6 +255,7 @@ $dummy  = pack "u", $var; check_count 'pack "u", $utf8';
 tie $var, "main", "\x{100}";
 pos$var = 0             ; check_count 'lvalue pos $utf8';
 $dummy=sprintf"%1s",$var; check_count 'sprintf "%1s", $utf8';
+$dummy=sprintf"%.1s",$var; check_count 'sprintf "%.1s", $utf8';
 $dummy  = substr$var,0,1; check_count 'substr $utf8';
 my $l   =\substr$var,0,1;
 $dummy  = $$l           ; check_count 'reading lvalue substr($utf8)';