Don't reload length in String::push#155847
Merged
rust-bors[bot] merged 1 commit intorust-lang:mainfrom Apr 28, 2026
Merged
Conversation
Same as in Vec::push_mut, we get `.len()` once at the start since it won't change in the `reserve()` call. Saves reloading the length after the allocation: https://godbolt.org/z/W3G165Gd7
Collaborator
|
r? @jhpratt rustbot has assigned @jhpratt. Use Why was this reviewer chosen?The reviewer was selected based on:
|
This comment was marked as outdated.
This comment was marked as outdated.
Contributor
Author
|
No, these are the flags: |
Member
|
Works for me. I'm surprised the compiler doesn't see through it. @bors r+ |
Contributor
jhpratt
added a commit
to jhpratt/rust
that referenced
this pull request
Apr 28, 2026
Don't reload length in String::push Same as in `Vec::push_mut`, we get `.len()` once at the start since it won't change in the `reserve()` call. Saves reloading the length after the allocation: https://godbolt.org/z/W3G165Gd7
jhpratt
added a commit
to jhpratt/rust
that referenced
this pull request
Apr 28, 2026
Don't reload length in String::push Same as in `Vec::push_mut`, we get `.len()` once at the start since it won't change in the `reserve()` call. Saves reloading the length after the allocation: https://godbolt.org/z/W3G165Gd7
This was referenced Apr 28, 2026
rust-bors Bot
pushed a commit
that referenced
this pull request
Apr 28, 2026
Rollup of 9 pull requests Successful merges: - #155381 (Fix a bug in `ChunkedBitSet::subtract`) - #155847 (Don't reload length in String::push) - #155858 (`slice::join`: borrow only once during length calc) - #155879 (enable pipe tests in Miri) - #155905 (Update LLVM to 22.1.4 (again)) - #155247 ([AIX] update linker default to bcdtors) - #155812 ([codex] tests: mark migrated UI tests as check-pass) - #155854 (Rename the diagnostic item for `std::sync::mpsc::Receiver`) - #155882 (Add regression test for #101363)
rust-timer
added a commit
that referenced
this pull request
Apr 28, 2026
Rollup merge of #155847 - DaniPopes:string-push-len, r=jhpratt Don't reload length in String::push Same as in `Vec::push_mut`, we get `.len()` once at the start since it won't change in the `reserve()` call. Saves reloading the length after the allocation: https://godbolt.org/z/W3G165Gd7
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Same as in
Vec::push_mut, we get.len()once at the start since it won't change in thereserve()call.Saves reloading the length after the allocation: https://godbolt.org/z/W3G165Gd7