Skip Menu |
 

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the PPI CPAN distribution.

Report information
The Basics
Id: 16836
Status: new
Priority: 0/
Queue: PPI

People
Owner: adamk [...] cpan.org
Requestors: nospam-abuse [...] bloodgate.com
Cc:
AdminCc:

Bug Information
Severity: Unimportant
Broken in: (no value)
Fixed in: (no value)



From: Tels <nospam-abuse [...] bloodgate.com>
To: bug-PPI [...] rt.cpan.org
Subject: PPI::Dumper - recursion problems
Date: Sun, 1 Jan 2006 12:02:33 +0100
Download (untitled) / with headers
text/plain 2.5k
-----BEGIN PGP SIGNED MESSAGE----- Moin, PPI::Dumper has a recursive dumping function called _dump: sub _dump { my $self = ref $_[0] ? shift : shift->new(shift); my $Element = _INSTANCE($_[0], 'PPI::Element') ? shift : $self->{root}; my $indent = shift || ''; my $output = shift || []; In its given state it has two problems: * deep recursion (f.i. deeply nested if-then-else) will warn. This can be fixed with a "no warnings 'recursion';" in it. * uses too much stack space and passes needlessly parameters round, wasting memory and slowing it down On each level, it will have: * self * element to dump * indend (growing, like "", " ", " ", " ", " ") *output (growing array on each level) The first two parameters are nec. but the second two need not to be passed around, respectively (indent) can be eliminated. The indentation can be inferered from the level, which in turn can be stored globally in the PPI::Dumper object. Thus we need not to keep the growing string around, and also need not to pass it to _element_string(). In addition, the output pointer ($output) can be stored at the object, so we need also not to pass it around. These changes eliminate quite a lot of stuff at the stack, and speed the dumping up. Small nitpick: $self->{indent_string} = join '', (' ' x $self->{display}->{indent}); The join is IMHO needless. I have also removed one needless "map" to increase the efficency of the string() method. Attached is a patch that implements all these changes. All tests pass on my system. In addition, it would be cool if PPI::Dumper could allow the following style in addition: # Create the dumper from a code ref my $Dumper = PPI::Dumper->new( \'$a = 1;' ); That would make writing code using it a little bit shorter :) Best wishes, Tels - -- Signed on Sun Jan 1 11:25:28 2006 with key 0x93B84C15. Visit my photo gallery at http://bloodgate.com/photos/ PGP key on http://bloodgate.com/tels.asc or per email. "Now, admittedly, it's critical software. This is the 'let's go kill people' software." -- Mark A. Welsh III -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.4 (GNU/Linux) iQEVAwUBQ7e2yXcLPEOTuEwVAQFkygf/UEtIt+8AHj4dA19EBGSYhEcnKq/27ga4 E0oouxB+lMVDiYXuvucdGlOpE8JzeChAvzSwrQajtEwUrWGgybPx2rpK67kfZdjA fwyHvv4rWoE/gU4Kv7fYIstU9AulFEQmAU2UQ/fKaefOwtmfyPYAGFvka7bxtE9D yXaz+zFLd3tF6Bisuufm1m0vs0nnrHoOXpS+LzSGCNpdmQ8HjFqab/0zqncWCJXT 396H9MnCJYwkOL48waEGS/z97eR8Dmu/BKbrRFvD6SR/a7hGV8MzlQgyGoFImvB0 WqsPuugsr7wqmCcimHzuC9se2BMEg2cTq/+sU4GVMpNV7RC3zwTwLg== =DCmg -----END PGP SIGNATURE-----

Message body is not shown because sender requested not to inline it.



This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.