Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

S_invlist_trim - don't SvPV_renew if SvLEN(invlist) is < PTRSIZE larger #23111

Open
wants to merge 1 commit into
base: blead
Choose a base branch
from

Conversation

richardleach
Copy link
Contributor

Currently, S_invlist_trim always calls SvPV_renew(invlist, <size>),
which is a macro wrapping a call to safesysrealloc().

However, SvLEN(invlist) is often already exactly the desired size,
or it is larger by less than the size of a pointer. With this commit,
such cases just return without calling SvPV_renew().


  • This set of changes does not require a perldelta entry.

Currently, `S_invlist_trim` always calls `SvPV_renew(invlist, <size>)`,
which is a macro wrapping a call to `safesysrealloc()`.

However, `SvLEN(invlist)` is often already exactly the desired size, or
it is larger by less than the size of a pointer. With this commit, such
cases just return without calling `SvPV_renew()`.
@richardleach
Copy link
Contributor Author

Tow comments:

  • It will still be common to try to resize SvLEN == 34 down to 25 bytes. Given that it's common for malloc implementations to increase chunk sizes by 2 x PTRLEN, should that be the check here too?
  • Allocated chunks will be pointer-aligned. 34 is not a multiple of 8! Maybe we should round up allocation sizes to a multiple of the pointer size generally?

@richardleach richardleach linked an issue Mar 17, 2025 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

S_invlist_trim maybe doesn't need to SvPV_renew every time?
1 participant