This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Optimise __SUB__ to a constant
authorFather Chrysostomos <sprout@cpan.org>
Fri, 25 Nov 2011 21:36:29 +0000 (13:36 -0800)
committerFather Chrysostomos <sprout@cpan.org>
Sat, 26 Nov 2011 22:33:46 +0000 (14:33 -0800)
commit1a35f9ffbd3ab4c89b6f5cad456b2b317c85e96e
tree66bf2690a6e643970b445f2109d5227f8035caed
parent65ae8d9907f85f9548082307d1fa0010e9fb4d41
Optimise __SUB__ to a constant

If __SUB__ is not inside a closure, it can be optimised to a constant.
We can only do this in the peephole optimiser, as we cannot tell
whether PL_compcv will become a closure until we reach the end
of the sub.

The __SUB__ op cannot simply be replaced with a const op, as the par-
ent op is not readily available in the peephole optimiser and, hence,
we cannot change its pointer.

So we have to convert the runcv op itself into a const op.  So it
has to be the same size.  This commit makes it a PVOP, since newPVOP,
unlike newSVOP, allows a null pv.  To avoid adding workarounds to B
modules, I put an exception in newPVOP’s assertion, instead of chang-
ing the type in regen/opcodes.

But B::Deparse still had to be updated to avoid infinite recursion.
dist/B-Deparse/Deparse.pm
op.c
toke.c