You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
SvPV_shrink_to_cur: don't be unrealistic, do include space for COW
The `SvPV_shrink_to_cur` macro shrinks an allocation to `SvCUR(sv) + 1`,
which does not include an additional byte for Copy-On-Write (COW).
GH#22116 - a902d92 - short-circuited
constant folding on CONST OPs, as this should be unnecessary. However,
Dave Mitchell noticed that it had the inadvertent effect of disabling
COW on SVs holding UTF8 string literals (e.g. `"\x{100}abcd"`).
When a CONST OP is created, `Perl_ck_svconst` should mark its SV as
being COW-able. But SVs built via `S_scan_const`, when that has
called `SvPV_shrink_to_cur`, have resulting `SvLEN(sv)` values that
fail the `SvCANCOW(sv)` test. Previously, constant folding had the
effect of copying the literal into a buffer large enough for COW.
This commit modifies `SvPV_shrink_to_cur` to: allocate an additional
byte to allow for subsequent COWing directly.
The macro has also been modified such that:
* No reallocation will be attempted if the saving is unrealistically
small, or otherwise no saving is likely to be achievable.
* The intended saving is compared with SvLEN(sv), which enables checks
at call sites to be simplified.
0 commit comments