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
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.