summaryrefslogtreecommitdiff
path: root/dist
diff options
context:
space:
mode:
authorFather Chrysostomos <sprout@cpan.org>2012-10-11 20:22:08 -0700
committerFather Chrysostomos <sprout@cpan.org>2012-10-11 23:07:36 -0700
commitef90d20ae1b70bb24316828c3249daee27459a7b (patch)
treea97bf2827b2c998d0b79c2d57603eca599853a08 /dist
parentfa4533d036f96ddb26c693c5b0c642b7cbc7d667 (diff)
downloadperl-ef90d20ae1b70bb24316828c3249daee27459a7b.tar.gz
Use const repl optimisation with s///e where possible
In those cases where s///e contains a single variable or a sequence that is folded to a const op, we can do away with substcont. PMf_EVAL means that there was an /e. But we don’t actually need to check that; instead we can just examine the op tree, which we have to do anyway. The op tree that s//$x/e and s//"constant"/e compile down to have a null (a do-block) containing a scope op (block with a single state- ment, as opposed to op_leave which represents multiple statements) containing a null followed by the constant or variable.
Diffstat (limited to 'dist')
-rw-r--r--dist/B-Deparse/Deparse.pm12
-rw-r--r--dist/B-Deparse/t/deparse.t2
2 files changed, 8 insertions, 6 deletions
diff --git a/dist/B-Deparse/Deparse.pm b/dist/B-Deparse/Deparse.pm
index 2a768c0e5a..07386d5626 100644
--- a/dist/B-Deparse/Deparse.pm
+++ b/dist/B-Deparse/Deparse.pm
@@ -4726,19 +4726,19 @@ sub pp_subst {
my $flags = "";
my $pmflags = $op->pmflags;
if (null($op->pmreplroot)) {
- $repl = $self->dq($kid);
+ $repl = $kid;
$kid = $kid->sibling;
} else {
$repl = $op->pmreplroot->first; # skip substcont
- while ($repl->name eq "entereval") {
+ }
+ while ($repl->name eq "entereval") {
$repl = $repl->first;
$flags .= "e";
- }
- if ($pmflags & PMf_EVAL) {
+ }
+ if ($pmflags & PMf_EVAL) {
$repl = $self->deparse($repl->first, 0);
- } else {
+ } else {
$repl = $self->dq($repl);
- }
}
my $extended = ($pmflags & PMf_EXTENDED);
if (null $kid) {
diff --git a/dist/B-Deparse/t/deparse.t b/dist/B-Deparse/t/deparse.t
index 3500d5b38c..d1c6cb0a1f 100644
--- a/dist/B-Deparse/t/deparse.t
+++ b/dist/B-Deparse/t/deparse.t
@@ -322,6 +322,8 @@ my $foo = "Ab\x{100}\200\x{200}\237Cd\000Ef\x{1000}\cA\x{2000}\cZ";
####
# s///e
s/x/'y';/e;
+s/x/$a;/e;
+s/x/complex_expression();/e;
####
# block
{ my $x; }