summaryrefslogtreecommitdiff
path: root/toke.c
diff options
context:
space:
mode:
authorFather Chrysostomos <sprout@cpan.org>2014-09-04 12:52:39 -0700
committerFather Chrysostomos <sprout@cpan.org>2014-09-04 13:39:49 -0700
commite3a09cfbb80ddcd428e9868bcf0a818a8c8cae0c (patch)
tree2b5cccb2584bd364f10adc7cda15ef74e456bc6d /toke.c
parente74036d119d0e671765ea56042a585158a686d2c (diff)
downloadperl-e3a09cfbb80ddcd428e9868bcf0a818a8c8cae0c.tar.gz
toke.c: Avoid extra sv_setpv for foo <newline> =>
When parsing something like time => if there is a global override, the parser transforms ‘time’ into ‘CORE::GLOBAL::time’ before it looks at the next line to see if there is a fat arrow. If it finds a fat arrow, it has to set the name back to ‘time’. After finding a fat arrow on the line following a bareword, it was setting the name to what appears in the program source, even when there was no global override. We can skip that most of the time. All that I said about global overrides applies to ‘our’ subs, too. ‘foo’ gets transformed into ‘ThatPackage::foo’ and needs to be changed back. I added a test, to make sure that is not accidentally broken. I took the liberty of changing ((SVOP*)pl_yylval.opval)->op_sv to sv at the same time, to make the code more readable.
Diffstat (limited to 'toke.c')
-rw-r--r--toke.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/toke.c b/toke.c
index 2a13031332..87a34dce92 100644
--- a/toke.c
+++ b/toke.c
@@ -6611,13 +6611,17 @@ Perl_yylex(pTHX)
if (*s == '=' && s[1] == '>' && !pkgname) {
op_free(rv2cv_op);
CLINE;
- /* This is our own scalar, created a few lines above,
- so this is safe. */
- SvREADONLY_off(cSVOPx(pl_yylval.opval)->op_sv);
- sv_setpv(((SVOP*)pl_yylval.opval)->op_sv, PL_tokenbuf);
- if (UTF && !IN_BYTES && is_utf8_string((U8*)PL_tokenbuf, len))
- SvUTF8_on(((SVOP*)pl_yylval.opval)->op_sv);
- SvREADONLY_on(cSVOPx(pl_yylval.opval)->op_sv);
+ if (gvp || (lex && !off)) {
+ assert (cSVOPx(pl_yylval.opval)->op_sv == sv);
+ /* This is our own scalar, created a few lines
+ above, so this is safe. */
+ SvREADONLY_off(sv);
+ sv_setpv(sv, PL_tokenbuf);
+ if (UTF && !IN_BYTES
+ && is_utf8_string((U8*)PL_tokenbuf, len))
+ SvUTF8_on(sv);
+ SvREADONLY_on(sv);
+ }
TERM(WORD);
}