Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add
impl AddAssign<char> for Cow<'_, str>
#66215New 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
Add
impl AddAssign<char> for Cow<'_, str>
#66215Changes from all commits
76a3b55
ed52372
342277f
9b55f6b
cd2ad6d
12a32e6
543a0b6
ea5f056
7d87504
d62e867
f2ac395
0704d9b
5623044
5d2184b
47d0179
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't quite right -- the amortized_new_size heuristic expects to receive the currently used capacity (how much is already used) and the requested extra capacity (how much is being added) as separate data points. In this AddAssign impl the currently used capacity is the length of the lhs Cow<str> and how much is being added is the size of the rhs char. Adding these together ahead of time would make the heuristic no longer applicable, or behave not as intended.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to avoid duplicating this sizing heuristic from the existing amortized_new_size in raw_vec.rs? I thought you had used amortized_new_size successfully in an earlier revision.
If we make changes to the heuristic in the future, it should only be in one place.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't look right to me -- we know base_capacity >= 0 so
max(base_capacity * 2, base_capacity)
is always the same asbase_capacity * 2
. Has it been written this way to account for integer overflow? If so, that needs to be handled differently; the overflowing multiplication would not be guaranteed to wrap around to 0.