summaryrefslogtreecommitdiff
path: root/toke.c
diff options
context:
space:
mode:
authorFather Chrysostomos <sprout@cpan.org>2014-09-03 18:21:18 -0700
committerFather Chrysostomos <sprout@cpan.org>2014-09-03 19:07:54 -0700
commitd484d78941e5be45f7c13c93622be0687ef90863 (patch)
tree8bf91d67929c3ddace68dab34e2f9ac1508ea202 /toke.c
parent294a536f50e99601d3257f44b17f0e40f73f0735 (diff)
downloadperl-d484d78941e5be45f7c13c93622be0687ef90863.tar.gz
Don’t call intuit_method twice for the same barewords
This calls intuit_method once: sub fooo; print foo bar This calls it twice: sub foo; print foo bar because seeing whether we are dealing with a bareword after ‘print’, ‘say’ etc. must happen *before* we look past the space after ‘foo’ to see whether ‘foo bar’ could be a method call. That’s because skipping a space could reset the internal variables that track whether we have just seen ‘print’. Hence, we end up with a call to intuit_method (i.e., is this a method?) inside the block that deals with print FOO. But then we have another call to intuit_method later that deals with the non-print cases. But the former can fall through to the latter if we don’t have a method call here. And then intuit_method is called again with exactly the same arguments. So we just repeat the check needlessly. Avoiding the call the second time (if we have already called it above) will allow the next commit to put a GV lookup that occurs only for the sake of intuit_method directly inside intuit_method, avoiding the need for that lookup for most barewords.
Diffstat (limited to 'toke.c')
-rw-r--r--toke.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/toke.c b/toke.c
index 4471f5287f..fec45dd1f7 100644
--- a/toke.c
+++ b/toke.c
@@ -6564,6 +6564,10 @@ Perl_yylex(pTHX)
: rv2cv_op_cv(rv2cv_op, RV2CVOPCV_RETURN_STUB);
}
+ /* Use this var to track whether intuit_method has been
+ called. intuit_method returns 0 or > 255. */
+ tmp = 1;
+
/* See if it's the indirect object for a list operator. */
if (PL_oldoldbufptr &&
@@ -6662,7 +6666,7 @@ Perl_yylex(pTHX)
/* If followed by a bareword, see if it looks like indir obj. */
- if (!orig_keyword
+ if (tmp == 1 && !orig_keyword
&& (isIDFIRST_lazy_if(s,UTF) || *s == '$')
&& (tmp = intuit_method(s, gv, cv))) {
op_free(rv2cv_op);