Skip to content

Commit dbe3741

Browse files
committed
Perl_vnewSVpvf - use the pattern length to size the new PV buffer
This function currently creates a new SVt_PV with a minimum string length buffer via: sv = newSV(1); Simple measurements from compiling perl show that this is often sufficient. When it isn't, the final buffer length is often close to strlen(pat). Common cases that require a realloc() now will not with this commit. In other cases, realloc()s will still be required, but the number will likely be smaller by one. Although min length & alloc behaviour can vary across platforms and compilers, the following numbers are likely indicative: |strlen(pat)|Inital SvLEN before|Initial SvLEN now|Final SvLEN| |-----------|-------------------|-----------------|-----------| |004|16|016|016| |058|16|060|060| |071|16|073|120| |104|16|106|106| |104|16|106|200| |122|16|124|124| |123|16|125|125| |123|16|125|168| |377|16|379|379|
1 parent 7a1fd31 commit dbe3741

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

sv.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10009,9 +10009,11 @@ Perl_vnewSVpvf(pTHX_ const char *const pat, va_list *const args)
1000910009

1001010010
PERL_ARGS_ASSERT_VNEWSVPVF;
1001110011

10012-
sv = newSV(1);
10012+
STRLEN patlen = strlen(pat);
10013+
10014+
sv = newSV(patlen);
1001310015
SvPVCLEAR_FRESH(sv);
10014-
sv_vcatpvfn_flags(sv, pat, strlen(pat), args, NULL, 0, NULL, 0);
10016+
sv_vcatpvfn_flags(sv, pat, patlen, args, NULL, 0, NULL, 0);
1001510017
return sv;
1001610018
}
1001710019

0 commit comments

Comments
 (0)