This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Deparse: detect hh changes properly
authorFather Chrysostomos <sprout@cpan.org>
Wed, 7 Dec 2011 07:29:21 +0000 (23:29 -0800)
committerFather Chrysostomos <sprout@cpan.org>
Wed, 7 Dec 2011 14:15:37 +0000 (06:15 -0800)
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
dist/B-Deparse/t/deparse.t

index c7bdec4..ed5493b 100644 (file)
@@ -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";
 }
 
index d47498c..a4284ef 100644 (file)
@@ -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 $_;