diff options
-rw-r--r-- | av.c | 3 | ||||
-rw-r--r-- | perl.h | 17 | ||||
-rw-r--r-- | pp_hot.c | 3 | ||||
-rw-r--r-- | sv.c | 8 |
4 files changed, 24 insertions, 7 deletions
@@ -177,7 +177,8 @@ Perl_av_extend_guts(pTHX_ AV *av, SSize_t key, SSize_t *maxp, SV ***allocp, PL_stack_max = PL_stack_base + newmax; } } else { /* there is no SV* array yet */ - *maxp = key < 3 ? 3 : key; + *maxp = key < PERL_ARRAY_NEW_MIN_KEY ? + PERL_ARRAY_NEW_MIN_KEY : key; { /* see comment above about newmax+1*/ MEM_WRAP_CHECK_s(*maxp, SV*, @@ -1593,6 +1593,23 @@ Use L</UV> to declare variables of the maximum usable size on this platform. #define MEM_SIZE Size_t +/* av_extend and analogues enforce a minimum number of array elements. + * This has been 4 elements (so a minimum key size of 3) for a long + * time, but the rationale behind this seems to have been lost to the + * mists of time. */ +#ifndef PERL_ARRAY_NEW_MIN_KEY +#define PERL_ARRAY_NEW_MIN_KEY 3 +#endif + +/* Functions like Perl_sv_grow mandate a minimum string size. + * This was 10 bytes for a long time, the rationale for which seems lost + * to the mists of time. However, since this does not correlate to what + * modern malloc implementations will actually return, it can be revised + * to be more appropriate. */ +#ifndef PERL_STRLEN_NEW_MIN +#define PERL_STRLEN_NEW_MIN 10 +#endif + /* Round all values passed to malloc up, by default to a multiple of sizeof(size_t) */ @@ -5152,7 +5152,8 @@ Perl_clear_defarray(pTHX_ AV* av, bool abandon) else { const SSize_t size = AvFILLp(av) + 1; /* The ternary gives consistency with av_extend() */ - AV *newav = newAV_alloc_x(size < 4 ? 4 : size); + AV *newav = newAV_alloc_x(size < PERL_ARRAY_NEW_MIN_KEY ? + PERL_ARRAY_NEW_MIN_KEY : size); AvREIFY_only(newav); PAD_SVl(0) = MUTABLE_SV(newav); SvREFCNT_dec_NN(av); @@ -1328,7 +1328,7 @@ Perl_sv_grow(pTHX_ SV *const sv, STRLEN newlen) if (newlen > SvLEN(sv)) { /* need more room? */ STRLEN minlen = SvCUR(sv); - minlen += (minlen >> PERL_STRLEN_EXPAND_SHIFT) + 10; + minlen += (minlen >> PERL_STRLEN_EXPAND_SHIFT) + PERL_STRLEN_NEW_MIN; if (newlen < minlen) newlen = minlen; #ifndef PERL_UNWARANTED_CHUMMINESS_WITH_MALLOC @@ -1402,10 +1402,8 @@ Perl_sv_grow_fresh(pTHX_ SV *const sv, STRLEN newlen) newlen++; #endif - /* 10 is a longstanding, hardcoded minimum length in sv_grow. */ - /* Just doing the same here for consistency. */ - if (newlen < 10) - newlen = 10; + if (newlen < PERL_STRLEN_NEW_MIN) + newlen = PERL_STRLEN_NEW_MIN; s = (char*)safemalloc(newlen); SvPV_set(sv, s); |