Skip to content

Commit a7ab896

Browse files
committed
when unCOWing a string, set SvCUR to 0
When a COW string is unCOWed, as well as setting SvPVX to NULL and SvLEN to 0, set SvCUR to 0 too. This is to avoid a later SvGROW on the same using the old SvCUR() value to calculate a roundup to the buffer size. Consider the following code: use Devel::Peek; for (1..3) { my $t; my $s = 'x' x 100; $t = $s; Dump $s; } Looking at the LEN line of the Dump output, we got on 5.20.0: LEN = 102 LEN = 135 LEN = 135 and after this commit, LEN = 102 LEN = 102 LEN = 102 As well as wasting space, this extra LEN was then triggering the 'skip COW if LEN >> CUR' mechanism, causing extra copies. See: [perl #121977] COWification seems expensive in PADMY variables
1 parent 694625f commit a7ab896

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

sv.c

+1
Original file line numberDiff line numberDiff line change
@@ -5031,6 +5031,7 @@ S_sv_uncow(pTHX_ SV * const sv, const U32 flags)
50315031
}
50325032
# endif
50335033
SvPV_set(sv, NULL);
5034+
SvCUR_set(sv, 0);
50345035
SvLEN_set(sv, 0);
50355036
if (flags & SV_COW_DROP_PV) {
50365037
/* OK, so we don't need to copy our buffer. */

0 commit comments

Comments
 (0)