This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Use sv_catpvn instead of sv_catsv in doop.c:do_join
authorFather Chrysostomos <sprout@cpan.org>
Sat, 18 Oct 2014 01:14:40 +0000 (18:14 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Sat, 18 Oct 2014 03:16:14 +0000 (20:16 -0700)
Bunchmarking shows that SvPV+sv_catpvn is faster that sv_catsv.  Why
exactly I don’t know, but perhaps fewer functions and flag checks
are the cause.

doop.c

diff --git a/doop.c b/doop.c
index 3b6f1e7..007ff5e 100644 (file)
--- a/doop.c
+++ b/doop.c
@@ -709,13 +709,22 @@ Perl_do_join(pTHX_ SV *sv, SV *delim, SV **mark, SV **sp)
 
     if (delimlen) {
        for (; items > 0; items--,mark++) {
+           STRLEN len;
+           const char *s;
            sv_catsv_nomg(sv,delim);
-           sv_catsv(sv,*mark);
+           s = SvPV_const(*mark,len);
+           sv_catpvn_flags(sv,s,len,
+                           DO_UTF8(*mark) ? SV_CATUTF8 : SV_CATBYTES);
        }
     }
     else {
        for (; items > 0; items--,mark++)
-           sv_catsv(sv,*mark);
+       {
+           STRLEN len;
+           const char *s = SvPV_const(*mark,len);
+           sv_catpvn_flags(sv,s,len,
+                           DO_UTF8(*mark) ? SV_CATUTF8 : SV_CATBYTES);
+       }
     }
     SvSETMAGIC(sv);
 }