summaryrefslogtreecommitdiff
path: root/sv.c
diff options
context:
space:
mode:
authorRichard Leach <richardleach@users.noreply.github.com>2022-11-08 23:40:06 +0000
committerYves Orton <demerphq@gmail.com>2022-11-21 12:40:10 +0100
commitdbf3614df92e720a9536b1cceb915a18ff2b8c08 (patch)
tree4a024e221c8ca84b8bbb14be28ebd890f7ffd610 /sv.c
parentb17e77fbd875a907749400afcdb9da990643edad (diff)
downloadperl-dbf3614df92e720a9536b1cceb915a18ff2b8c08.tar.gz
Extract minimum PV buffer/AV element size to common definitions
In a nutshell, for a long time the minimum PV length (hardcoded in Perl_sv_grow) has been 10 bytes and the minimum AV array size (hardcoded in av_extend_guts) has been 4 elements. These numbers have been used elsewhere for consistency (e.g. Perl_sv_grow_fresh) in the past couple of development cycles. Having a standard definition, rather than hardcoding in multiple places, is more maintainable. This commit therefore introduces into perl.h: PERL_ARRAY_NEW_MIN_KEY PERL_STRLEN_NEW_MIN (Note: Subsequent commit(s) will actually change the values.)
Diffstat (limited to 'sv.c')
-rw-r--r--sv.c8
1 files changed, 3 insertions, 5 deletions
diff --git a/sv.c b/sv.c
index 8d80b5e31b..96283839f5 100644
--- a/sv.c
+++ b/sv.c
@@ -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);