summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFather Chrysostomos <sprout@cpan.org>2014-10-19 14:14:05 -0700
committerFather Chrysostomos <sprout@cpan.org>2014-10-20 12:38:06 -0700
commit810a07df93924c82fc5bbe83c8f12a0def2fb61d (patch)
treebdc1bc1b5a7834718250e9b4fcb247388d1c04a9
parentb3153e044595a17d3f7e3c62468beb8c8f8ac96d (diff)
downloadperl-810a07df93924c82fc5bbe83c8f12a0def2fb61d.tar.gz
Call string overloading once in join($ov,...)
-rw-r--r--doop.c7
-rw-r--r--t/op/join.t9
2 files changed, 11 insertions, 5 deletions
diff --git a/doop.c b/doop.c
index 007ff5e2e3..62edb06297 100644
--- a/doop.c
+++ b/doop.c
@@ -669,12 +669,10 @@ Perl_do_join(pTHX_ SV *sv, SV *delim, SV **mark, SV **sp)
I32 items = sp - mark;
STRLEN len;
STRLEN delimlen;
+ const char * const delims = SvPV_const(delim, delimlen);
PERL_ARGS_ASSERT_DO_JOIN;
- (void) SvPV_const(delim, delimlen); /* stringify and get the delimlen */
- /* SvCUR assumes it's SvPOK() and woe betide you if it's not. */
-
mark++;
len = (items > 0 ? (delimlen * (items - 1) ) : 0);
SvUPGRADE(sv, SVt_PV);
@@ -708,10 +706,11 @@ Perl_do_join(pTHX_ SV *sv, SV *delim, SV **mark, SV **sp)
}
if (delimlen) {
+ const U32 delimflag = DO_UTF8(delim) ? SV_CATUTF8 : SV_CATBYTES;
for (; items > 0; items--,mark++) {
STRLEN len;
const char *s;
- sv_catsv_nomg(sv,delim);
+ sv_catpvn_flags(sv,delims,delimlen,delimflag);
s = SvPV_const(*mark,len);
sv_catpvn_flags(sv,s,len,
DO_UTF8(*mark) ? SV_CATUTF8 : SV_CATBYTES);
diff --git a/t/op/join.t b/t/op/join.t
index f98b5dbe81..4117d49cff 100644
--- a/t/op/join.t
+++ b/t/op/join.t
@@ -6,7 +6,7 @@ BEGIN {
require './test.pl';
}
-plan tests => 26;
+plan tests => 28;
@x = (1, 2, 3);
is( join(':',@x), '1:2:3', 'join an array with character');
@@ -117,3 +117,10 @@ is( $f, 'baeak', 'join back to self, self is join character');
is( $ju2, $u );
}
+package o { use overload q|""| => sub { ${$_[0]}++ } }
+{
+ my $o = bless \(my $dummy = "a"), o::;
+ $_ = join $o, 1..10;
+ is $_, "1a2a3a4a5a6a7a8a9a10", 'join, $overloaded, LIST';
+ is $$o, "b", 'overloading was called once on overloaded separator';
+}