Skip to content

Conversation

@MahdiBM
Copy link
Contributor

@MahdiBM MahdiBM commented Dec 15, 2025

By a quick look, I think there are more places that could use this "optimization" of reserving-capacity beforehand.

I'm doing this PR for now, just to see if I'm missing something or if this is an acceptable change.

@MahdiBM MahdiBM requested a review from a team as a code owner December 15, 2025 08:17
@inlinable
public mutating func append<S: Sequence>(contentsOf newElements: __owned S)
where S.Element == Element {
reserveCapacity(newElements.underestimatedCount)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could use newElements.count(where: { _ in true }) to get the count as well.
LMK if you think I should do that.
Or even If I should do something more complicated, like using underestimatedCount by default, but if underestimatedCount is 0 then try count(where: { _ in true }) as well.

@MahdiBM
Copy link
Contributor Author

MahdiBM commented Dec 15, 2025

Interesting. I just noticed this PR: #65927

Does this still apply?

@MahdiBM
Copy link
Contributor Author

MahdiBM commented Dec 15, 2025

Reading the PR it does sound like this still applies.

@MahdiBM MahdiBM closed this Dec 15, 2025
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.

1 participant