This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
toke.c: Merge some mad and sane code
authorFather Chrysostomos <sprout@cpan.org>
Fri, 23 Aug 2013 06:06:30 +0000 (23:06 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Fri, 23 Aug 2013 07:09:34 +0000 (00:09 -0700)
These two code paths are now nearly identical.  However, one uses s as
its cursor; the other uses d therefor while using s to remember the
previous position.  If we switch the uses of d and s, then outside of
PL_madskills we don’t even need to set d.

toke.c

diff --git a/toke.c b/toke.c
index fd1df9d..6e435a9 100644 (file)
--- a/toke.c
+++ b/toke.c
@@ -5593,17 +5593,19 @@ Perl_yylex(pTHX)
                s = SKIPSPACE0(s);
            }
            else {
-                   d = s;
-                   while (d < PL_bufend && *d != '\n')
-                       d++;
-                   if (d < PL_bufend)
+#endif
+                   if (PL_madskills) d = s;
+                   while (s < PL_bufend && *s != '\n')
+                       s++;
+                   if (s < PL_bufend)
                    {
-                       d++;
-                       if (d < PL_bufend)
-                           incline(d);
+                       s++;
+                       if (s < PL_bufend)
+                           incline(s);
                    }
-                   else if (d > PL_bufend) /* Found by Ilya: feed random input to Perl. */
+                   else if (s > PL_bufend) /* Found by Ilya: feed random input to Perl. */
                      Perl_croak(aTHX_ "panic: input overflow");
+#ifdef PERL_MAD
                    if (PL_madskills && CopLINE(PL_curcop) >= 1) {
                        if (!PL_thiswhite)
                            PL_thiswhite = newSVpvs("");
@@ -5611,22 +5613,9 @@ Perl_yylex(pTHX)
                            sv_setpvs(PL_thiswhite, "");
                            PL_faketokens = 0;
                        }
-                       sv_catpvn(PL_thiswhite, s, d - s);
+                       sv_catpvn(PL_thiswhite, d, s - d);
                    }
-                   s = d;
            }
-#else
-           while (s < PL_bufend && *s != '\n')
-               s++;
-           if (s < PL_bufend)
-           {
-               s++;
-               if (s < PL_bufend)
-                   incline(s);
-           }
-               
-           else if (s > PL_bufend) /* Found by Ilya: feed random input to Perl. */
-             Perl_croak(aTHX_ "panic: input overflow");
 #endif
        }
        goto retry;