[perl #49190] Don’t prematurely optimise s/foo/bar$baz/
$baz could be aliased to a package variable, so we do need to recon-
catenate for every iteration of s///g. For s/// without /g, only one
more op will be executed, so the speed difference is negligible.
The only cases we can optimise in terms of skipping the evaluation of
the ops on the rhs (by eliminating the substconst op) are s//constant/
and s//$single_variable/. Anything more complicated causes bugs.
A recent commit made s/foo/$bar/g re-stringify $bar for each iteration
(though without having to reevaluate the ops that return $bar). So we
no longer have to special-case match vars at compile time.
This means that s/foo/bar$baz/g will be slower (and less buggy), but
s/foo/$1/g will be faster.
This also caused an existing taint but in pp_subst to surface. If
get-magic turns off taint on a replacement string, it should not be
considered tainted. So the taint check on the replacement should come
*after* the stringification. This applies to the constant replacement
optimisation. pp_substcont was already doing this correctly.