This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Don’t call intuit_method twice for the same barewords
authorFather Chrysostomos <sprout@cpan.org>
Thu, 4 Sep 2014 01:21:18 +0000 (18:21 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Thu, 4 Sep 2014 02:07:54 +0000 (19:07 -0700)
commitd484d78941e5be45f7c13c93622be0687ef90863
tree8bf91d67929c3ddace68dab34e2f9ac1508ea202
parent294a536f50e99601d3257f44b17f0e40f73f0735
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.
toke.c