From 5c9ae74dcaf4a16d67145fc3ea876a42aeb5c0b3 Mon Sep 17 00:00:00 2001 From: Father Chrysostomos Date: Wed, 8 Aug 2012 23:12:59 -0700 Subject: [PATCH] toke.c: Set PL_lex_state less when scanning formats MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This (in yylex) is the only code that calls scan_formline: case LEX_FORMLINE: PL_lex_state = PL_parser->form_lex_state; s = scan_formline(PL_bufptr); if (!PL_lex_formbrack) { formbrack = 1; goto rightbracket; } PL_bufptr = s; return yylex(); } It is only reached when PL_lex_state is LEX_FORMLINE. scan_formline itself does not even look at PL_lex_state. It does set it, though, unless it has reached the end of the format (setting PL_lex_formbrack to 0) or the end of input. This means we end up flipping it back and forth between two values. We don’t have to set PL_lex_state before scan_formline() at all. Hav- ing scan_formline only set it when it does not need to be LEX_FORMLINE simplifies things, resulting in less code and fewer assignments. --- toke.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/toke.c b/toke.c index 49a29e6..2ecebad 100644 --- a/toke.c +++ b/toke.c @@ -4783,7 +4783,6 @@ Perl_yylex(pTHX) return yylex(); case LEX_FORMLINE: - PL_lex_state = PL_parser->form_lex_state; s = scan_formline(PL_bufptr); if (!PL_lex_formbrack) { @@ -10713,16 +10712,15 @@ S_scan_formline(pTHX_ register char *s) incline(s); } enough: + if (!SvCUR(stuff) || needargs) + PL_lex_state = PL_parser->form_lex_state; if (SvCUR(stuff)) { PL_expect = XSTATE; if (needargs) { - PL_lex_state = PL_parser->form_lex_state; start_force(PL_curforce); NEXTVAL_NEXTTOKE.ival = 0; force_next(FORMLBRACK); } - else - PL_lex_state = LEX_FORMLINE; if (!IN_BYTES) { if (UTF && is_utf8_string((U8*)SvPVX_const(stuff), SvCUR(stuff))) SvUTF8_on(stuff); -- 2.7.4