From: Nicholas Clark Date: Tue, 26 Feb 2008 19:17:38 +0000 (+0000) Subject: If we have malloced_size() available, then avoid rounding up the string X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=98653f182f8d34d630c65229237c0d55f664e886;p=p5sagit%2Fp5-mst-13.2.git If we have malloced_size() available, then avoid rounding up the string to the next (guessed) plausible alignment size, and instead find out how much memory was actually allocated, so that we can set this in the scalar's SvLEN(). This way, sv_grow() will be called far less often. p4raw-id: //depot/perl@33377 --- diff --git a/sv.c b/sv.c index be66ac8..11e7739 100644 --- a/sv.c +++ b/sv.c @@ -1479,15 +1479,10 @@ Perl_sv_grow(pTHX_ register SV *const sv, register STRLEN newlen) s = SvPVX_mutable(sv); if (newlen > SvLEN(sv)) { /* need more room? */ +#ifndef MYMALLOC newlen = PERL_STRLEN_ROUNDUP(newlen); - if (SvLEN(sv) && s) { -#ifdef MYMALLOC - const STRLEN l = malloced_size((void*)SvPVX_const(sv)); - if (newlen <= l) { - SvLEN_set(sv, l); - return s; - } else #endif + if (SvLEN(sv) && s) { s = (char*)saferealloc(s, newlen); } else { @@ -1497,7 +1492,14 @@ Perl_sv_grow(pTHX_ register SV *const sv, register STRLEN newlen) } } SvPV_set(sv, s); +#ifdef MYMALLOC + /* Do this here, do it once, do it right, and then we will never get + called back into sv_grow() unless there really is some growing + needed. */ + SvLEN_set(sv, malloced_size(s)); +#else SvLEN_set(sv, newlen); +#endif } return s; }