This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Perl_sv_vcatpvfn_flags: move %*v handling earlier
authorDavid Mitchell <davem@iabyn.com>
Fri, 26 May 2017 21:19:44 +0000 (22:19 +0100)
committerDavid Mitchell <davem@iabyn.com>
Wed, 7 Jun 2017 08:11:04 +0000 (09:11 +0100)
Where the v flag appears, and it has non-default separator, i.e.
*v or *NNN$v, retrieve the next or NNNth arg (which defines the separator)
earlier - as soon as we encounter the v flag. This should in theory make
no functional difference since no args are processed between those two
points (so no chance of us stealing something else's arg).

Doing it ealrier makes the conditions simpler (we don't have to check for
(vectorize && vectorarg) later).

The whole code block has been moved as-is with no changes apart from
whitespace.

sv.c

diff --git a/sv.c b/sv.c
index b33792a..1355485 100644 (file)
--- a/sv.c
+++ b/sv.c
@@ -12003,6 +12003,27 @@ Perl_sv_vcatpvfn_flags(pTHX_ SV *const sv, const char *const pat, const STRLEN p
                evix = ewix;
                ewix = 0;
                asterisk = FALSE;
+                /* vectorizing, but not with the default "." */
+                if (args)
+                    vecsv = va_arg(*args, SV*);
+                else if (evix) {
+                    FETCH_VCATPVFN_ARGUMENT(
+                        vecsv, evix > 0 && evix <= svmax, svargs[evix-1]);
+                } else {
+                    FETCH_VCATPVFN_ARGUMENT(
+                        vecsv, svix < svmax, svargs[svix++]);
+                }
+                dotstr = SvPV_const(vecsv, dotstrlen);
+                /* Keep the DO_UTF8 test *after* the SvPV call, else things go
+                   bad with tied or overloaded values that return UTF8.  */
+                if (DO_UTF8(vecsv))
+                    is_utf8 = TRUE;
+                else if (has_utf8) {
+                    vecsv = sv_mortalcopy(vecsv);
+                    sv_utf8_upgrade(vecsv);
+                    dotstr = SvPV_const(vecsv, dotstrlen);
+                    is_utf8 = TRUE;
+                }
            }
            vectorize = TRUE;
            goto tryasterisk;
@@ -12017,29 +12038,6 @@ Perl_sv_vcatpvfn_flags(pTHX_ SV *const sv, const char *const pat, const STRLEN p
            width = expect_number(&q);
        }
 
-       if (vectorize && vectorarg) {
-           /* vectorizing, but not with the default "." */
-           if (args)
-               vecsv = va_arg(*args, SV*);
-           else if (evix) {
-                FETCH_VCATPVFN_ARGUMENT(
-                    vecsv, evix > 0 && evix <= svmax, svargs[evix-1]);
-           } else {
-                FETCH_VCATPVFN_ARGUMENT(
-                    vecsv, svix < svmax, svargs[svix++]);
-           }
-           dotstr = SvPV_const(vecsv, dotstrlen);
-           /* Keep the DO_UTF8 test *after* the SvPV call, else things go
-              bad with tied or overloaded values that return UTF8.  */
-           if (DO_UTF8(vecsv))
-               is_utf8 = TRUE;
-           else if (has_utf8) {
-               vecsv = sv_mortalcopy(vecsv);
-               sv_utf8_upgrade(vecsv);
-               dotstr = SvPV_const(vecsv, dotstrlen);
-               is_utf8 = TRUE;
-           }               
-       }
 
        if (asterisk) {
             int i;