From c306e834a2e7e21d20699178dd251b8b8171bc14 Mon Sep 17 00:00:00 2001 From: Father Chrysostomos Date: Tue, 6 Dec 2011 23:29:21 -0800 Subject: [PATCH] Deparse: detect hh changes properly MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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. --- dist/B-Deparse/Deparse.pm | 11 ++++++----- dist/B-Deparse/t/deparse.t | 8 ++++++++ 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/dist/B-Deparse/Deparse.pm b/dist/B-Deparse/Deparse.pm index c7bdec4..ed5493b 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 d47498c..a4284ef 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 $_; -- 2.7.4