From 9fa5cce2ac5fe91228c7c54739f581c98f0738ef Mon Sep 17 00:00:00 2001 From: Nicholas Clark Date: Sat, 7 Oct 2006 23:42:56 +0000 Subject: [PATCH] Yves said that the XS version of Data::Dumper was inefficient because it keeps triggering realloc() due to sv_cat(). Here's a rather brute force approach to pre-stretching the buffer - if there are less than 40 bytes free, grow it by 50%. Surprisingly effective for my test program ./perl -Ilib -MData::Dumper -MStorable=retrieve -we \ 'print Dumper(retrieve(shift))' ~/.cpan/Metadata >/dev/null Before real 2m42.921s user 1m43.321s sys 0m55.611s After real 0m5.205s user 0m4.885s sys 0m0.255s Same 25M of output, byte for byte. :-) p4raw-id: //depot/perl@28963 --- ext/Data/Dumper/Dumper.xs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ext/Data/Dumper/Dumper.xs b/ext/Data/Dumper/Dumper.xs index 36383dc..dbdc2d6 100644 --- a/ext/Data/Dumper/Dumper.xs +++ b/ext/Data/Dumper/Dumper.xs @@ -274,6 +274,9 @@ DD_dump(pTHX_ SV *val, const char *name, STRLEN namelen, SV *retval, HV *seenhv, if (!val) return 0; + if (SvTYPE(retval) >= SVt_PV && (SvLEN(retval) - SvCUR(retval)) < 40) { + sv_grow(retval, SvCUR(retval) * 1.5); + } realtype = SvTYPE(val); if (SvGMAGICAL(val)) -- 2.7.4