[perl #26986] Skip subst const repl optimisation for logops
authorFather Chrysostomos <sprout@cpan.org>
Tue, 9 Oct 2012 20:34:54 +0000 (13:34 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Wed, 10 Oct 2012 00:44:16 +0000 (17:44 -0700)
commit86e69b18632c87a8d5d07a35439df8d22533b675
treee8d679c0659ec30bb4a48b49fe8d3c9c8e5aa5b2
parentcdc4a17406010fd176cecceef1e025e34a60202f
[perl #26986] Skip subst const repl optimisation for logops

pm_runtime iterates through the ops that make up the replacement part
of s///, to see whether the ops on the rhs can have side effects or
contain match vars (in which case they must only be evaluted after the
pattern).  If they do not have side-effects, the rhs is presumed to be
constant and evaluated first, and then pp_subst hangs on to the return
value and reuses it in each iteration of s///g.

This iteration simply follows op_next pointers.  Logops are not that
simple, so it is possible to hide match vars inside them, resulting in
incorrect optimisations:

"g" =~ /(.)/;
@l{'a'..'z'} = 'a'..'z';
$_ = "hello";
s/(.)/$l{$a||$1}/g;
print;
__END__
ggggg

This commit skips the optimisation whenever a logop is present.

This does not fix all the optimisation problems.  See ticket #49190.
op.c
t/re/subst.t