This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Data::Dumper: move sortkeys setting into style struct
authorAaron Crane <arc@cpan.org>
Tue, 8 Dec 2015 14:42:43 +0000 (14:42 +0000)
committerAaron Crane <arc@cpan.org>
Wed, 16 Dec 2015 00:01:08 +0000 (00:01 +0000)
commite46750ce23791d111ea7e91135cd62b776ab9fba
treebe7345567ba1e0e2e49036d602828accd0a49a49
parente8251b48709604526e60bd37202eecfbbfcc71fa
Data::Dumper: move sortkeys setting into style struct

On Perl 5.6, there is no sortsv() function available to XS code, so
Data::Dumper used a Perl helper function. The name of that helper function
was allocated as a (mortal) SV, but that was done lazily, the first time the
helper was needed. This meant that the "sortkeys" C variable was mutable,
and therefore it couldn't be easily moved to the struct.

I think it's a better trade-off to allocate the SV in all cases under 5.6:
when dumping a data structure containing no hashes, we now allocate this SV
unnecessarily, but we save an extra pointer on the stack in every recursive
call frame.

In addition, Data::Dumper doesn't currently work on 5.6 as far as I can tell,
so this change certainly doesn't make anything any worse. I've nonetheless
attempted to restore 5.6 compatibility in this narrow area surrounding the
sortkeys option: in particular, a sortsv() call appeared in code that was
compiled under 5.6, but has now been moved to a block that's compiled only
under later Perls. I haven't been able to test this change on 5.6, though.
dist/Data-Dumper/Dumper.xs