Branch: refs/heads/blead
  Home:   https://github.com/Perl/perl5
  Commit: c6b821f85462bcf3040e98cfef16ebe9f8ad9961
      
https://github.com/Perl/perl5/commit/c6b821f85462bcf3040e98cfef16ebe9f8ad9961
  Author: Richard Leach <richardle...@users.noreply.github.com>
  Date:   2025-08-09 (Sat, 09 Aug 2025)

  Changed paths:
    M embed.fnc
    M perl.h
    M proto.h

  Log Message:
  -----------
  Add Perl_expected_size stub macro

Passed a number of bytes, this macro will return:
* PERL_STRLEN_NEW_MIN if that is larger than the argument value
* the argument value rounded up to PTRSIZE

The intention is to later convert `Perl_expected_size` into a
function that has some knowledge of the underlying malloc library's
behaviour and can return values more reflective of the actual
useable allocation size for the specified number of bytes.

This can aid in reducing unnecessary calls to realloc().


  Commit: b1f270f0cbf67fc18c949626d91f0f1856747fe5
      
https://github.com/Perl/perl5/commit/b1f270f0cbf67fc18c949626d91f0f1856747fe5
  Author: Richard Leach <richardle...@users.noreply.github.com>
  Date:   2025-08-09 (Sat, 09 Aug 2025)

  Changed paths:
    M sv.h

  Log Message:
  -----------
  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 - a902d92a78262a0fd111789742f9c9e2a7fa2f42 - 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` so that it adds an
additional byte to allow for subsequent direct COWing.

The macro has also been modified to use the new `expected_size` macro,
so that reallocation will not be attempted if the resulting buffer
size is not going to be any smaller.

The intended saving is compared with SvLEN(sv), rather than SvCUR(sv),
as this also helps in cases such as SvCUR(sv) having previously been
set to zero and a size smaller than PERL_STRLEN_NEW_MIN is requested.
This will also enable some size checks at call sites to be simplified.


  Commit: d9990217414e3f4066c8548f940910f990e69d40
      
https://github.com/Perl/perl5/commit/d9990217414e3f4066c8548f940910f990e69d40
  Author: Richard Leach <richardle...@users.noreply.github.com>
  Date:   2025-08-09 (Sat, 09 Aug 2025)

  Changed paths:
    M toke.c

  Log Message:
  -----------
  Simplify SvPV_shrink_to_cur() usage in toke.c

The previous commit modified the definition of `SvPV_shrink_to_cur` so that
it does not attempt to reallocate to make unrealistic savings. That made
some of the condition checks in toke.c redundant, so this commit removes
those.


  Commit: 4a38ddc0281c99685df59b2e1e946a7360703884
      
https://github.com/Perl/perl5/commit/4a38ddc0281c99685df59b2e1e946a7360703884
  Author: Richard Leach <richardle...@users.noreply.github.com>
  Date:   2025-08-09 (Sat, 09 Aug 2025)

  Changed paths:
    M pod/perldelta.pod

  Log Message:
  -----------
  Perldelta for Perl_expected_size / SvPV_shrink_to_cur


Compare: https://github.com/Perl/perl5/compare/89b92b61562c...4a38ddc0281c

To unsubscribe from these emails, change your notification settings at 
https://github.com/Perl/perl5/settings/notifications

Reply via email to