summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFather Chrysostomos <sprout@cpan.org>2011-12-06 23:29:21 -0800
committerFather Chrysostomos <sprout@cpan.org>2011-12-07 06:15:37 -0800
commitc306e834a2e7e21d20699178dd251b8b8171bc14 (patch)
tree4b5c3fcdc3231e479b03194426c281c8d4805e6a
parent70397346423dee021539e9ebb34b4cf1e097ca50 (diff)
downloadperl-c306e834a2e7e21d20699178dd251b8b8171bc14.tar.gz
Deparse: detect hh changes properly
The hack to check whether the hint hash has changed doesn’t work. One actually has to iterate through the hash. Since declare_hinthash does that already, just call it. The change to declare_hinthash to return an empty list instead of '' is one of those theoretical speed-ups. It results in one less state- ment and two fewer method calls in its caller.
-rw-r--r--dist/B-Deparse/Deparse.pm11
-rw-r--r--dist/B-Deparse/t/deparse.t8
2 files changed, 14 insertions, 5 deletions
diff --git a/dist/B-Deparse/Deparse.pm b/dist/B-Deparse/Deparse.pm
index c7bdec4249..ed5493b0f7 100644
--- a/dist/B-Deparse/Deparse.pm
+++ b/dist/B-Deparse/Deparse.pm
@@ -1451,11 +1451,12 @@ sub pp_nextstate {
$self->{'hints'} = $hints;
}
- # hack to check that the hint hash hasn't changed
if ($] > 5.009 &&
- "@{[sort %{$self->{'hinthash'} || {}}]}"
- ne "@{[sort %{$op->hints_hash->HASH || {}}]}") {
- push @text, declare_hinthash($self->{'hinthash'}, $op->hints_hash->HASH, $self->{indent_size});
+ @text != push @text, declare_hinthash(
+ $self->{'hinthash'}, $op->hints_hash->HASH,
+ $self->{indent_size}
+ )
+ ) {
$self->{'hinthash'} = $op->hints_hash->HASH;
}
@@ -1527,7 +1528,7 @@ sub declare_hinthash {
push @decls, qq(delete \$^H{'$key'};);
}
}
- @decls or return '';
+ @decls or return;
return join("\n" . (" " x $indent), "BEGIN {", @decls) . "\n}\n";
}
diff --git a/dist/B-Deparse/t/deparse.t b/dist/B-Deparse/t/deparse.t
index d47498cf59..a4284ef33f 100644
--- a/dist/B-Deparse/t/deparse.t
+++ b/dist/B-Deparse/t/deparse.t
@@ -809,3 +809,11 @@ BEGIN { $^H{'foo'} = undef; }
}
BEGIN { $^H{q[']} = '('; }
print $_;
+####
+# hint hash changes that serialise the same way with sort %hh
+BEGIN { $^H{'a'} = 'b'; }
+{
+ BEGIN { $^H{'b'} = 'a'; delete $^H{'a'}; }
+ print $_;
+}
+print $_;