This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Data::Dumper: replace pointer with local variable
authorAaron Crane <arc@cpan.org>
Tue, 8 Dec 2015 15:03:28 +0000 (15:03 +0000)
committerAaron Crane <arc@cpan.org>
Wed, 16 Dec 2015 00:01:09 +0000 (00:01 +0000)
commit3f2b063d143511f8b9027419d9cc90e49238a68e
treeb93dd5cf74f7dfc410eb510a103a65e8f16b891e
parente46750ce23791d111ea7e91135cd62b776ab9fba
Data::Dumper: replace pointer with local variable

The recursive dumping function uses a "level" variable to keep track of how
deep in the data structure it is. Previously, this variable was allocated on
the stack at the top level, and a pointer to that stack variable was passed
to each recursive invocation. Each recursive step was careful to increment
and decrement the pointed-to value at the right time. The consequence of
this approach is that understanding what's going involves mentally tracking
this state throughout the entire thousand-line function.

This change therefore replaces that pointer-to-mutable-int with a plain int
parameter; when the dumper invokes itself recursively, it simply adds one to
the level as needed. This seems much simpler to me.

This may also be faster: not only is the pointer indirection removed for
accesses to the variable, but on platforms where pointers are wider than I32
(including typical 64-bit systems), less memory is used on the stack for the
call frames.
dist/Data-Dumper/Dumper.xs