toke.c:yylex:KEY_sub can use PL_tokenbuf to begin with
authorFather Chrysostomos <sprout@cpan.org>
Wed, 4 Jul 2012 21:09:46 +0000 (14:09 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Sun, 16 Sep 2012 05:44:55 +0000 (22:44 -0700)
There is no need to allocate a separate ‘tmpbuf’ and then copy it into
PL_tokenbuf afterwards.

toke.c

diff --git a/toke.c b/toke.c
index 8f5475c..901ebe9 100644 (file)
--- a/toke.c
+++ b/toke.c
@@ -8195,7 +8195,7 @@ Perl_yylex(pTHX)
        case KEY_sub:
          really_sub:
            {
-               char tmpbuf[sizeof PL_tokenbuf];
+               char * const tmpbuf = PL_tokenbuf + 1;
                SSize_t tboffset = 0;
                expectation attrful;
                bool have_name, have_proto;
@@ -8226,7 +8226,8 @@ Perl_yylex(pTHX)
                    attrful = XATTRBLOCK;
                    /* remember buffer pos'n for later force_word */
                    tboffset = s - PL_oldbufptr;
-                   d = scan_word(s, tmpbuf, sizeof tmpbuf, TRUE, &len);
+                   d = scan_word(s, tmpbuf, sizeof PL_tokenbuf - 1, TRUE,
+                                 &len);
 #ifdef PERL_MAD
                    if (PL_madskills)
                        nametoke = newSVpvn_flags(s, d - s, SvUTF8(PL_linestr));
@@ -8243,8 +8244,6 @@ Perl_yylex(pTHX)
                    have_name = TRUE;
 
                    *PL_tokenbuf = '&';
-                   Copy(tmpbuf, PL_tokenbuf+1, len, char);
-                   PL_tokenbuf[len+1] = '\0';
 
 #ifdef PERL_MAD
                    start_force(0);