This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[perl #69875] Slow down split in scalar context :-)
authorFather Chrysostomos <perlbug-followup@perl.org>
Sat, 31 Oct 2009 15:15:08 +0000 (16:15 +0100)
committerRafael Garcia-Suarez <rgs@consttype.org>
Sat, 31 Oct 2009 15:16:35 +0000 (16:16 +0100)
The patch to speed up split in scalar context broke Font::GlyphNames,
because it stops scalar(@array = split) from working. The attached
patch fixes this, and ineluctably slows it down slightly.

(Patch amended by replacing the 2nd GIMME_V macro call by the gimme
variable)

pp.c
t/op/split.t

diff --git a/pp.c b/pp.c
index 80bb590..d0022fc 100644 (file)
--- a/pp.c
+++ b/pp.c
@@ -4894,7 +4894,7 @@ PP(pp_split)
     I32 realarray = 0;
     I32 base;
     const I32 gimme = GIMME_V;
-    const bool gimme_scalar = (GIMME_V == G_SCALAR);
+    bool gimme_scalar;
     const I32 oldsave = PL_savestack_ix;
     U32 make_mortal = SVs_TEMP;
     bool multiline = 0;
@@ -4968,6 +4968,8 @@ PP(pp_split)
        multiline = 1;
     }
 
+    gimme_scalar = gimme == G_SCALAR && !ary;
+
     if (!limit)
        limit = maxiters + 2;
     if (RX_EXTFLAGS(rx) & RXf_WHITE) {
index 6b38b43..da12b3e 100644 (file)
@@ -6,7 +6,7 @@ BEGIN {
     require './test.pl';
 }
 
-plan tests => 250;
+plan tests => 251;
 
 $FS = ':';
 
@@ -460,3 +460,11 @@ is($cnt, scalar(@ary));
     () = split m/,/, "", BANG;
     ok(1);
 }
+
+{
+    # Bug #XXXXX
+    # 'Hybrid' scalar-and-array context
+    scalar(our @PATH = split /::/, "Font::GlyphNames");
+           # 'my' doesn't trigger the bug
+    is "@PATH", "Font GlyphNames", "hybrid scalar-and-array context";
+}