Skip to content

Don't reload length in String::push#155847

Merged
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
DaniPopes:string-push-len
Apr 28, 2026
Merged

Don't reload length in String::push#155847
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
DaniPopes:string-push-len

Conversation

@DaniPopes
Copy link
Copy Markdown
Contributor

@DaniPopes DaniPopes commented Apr 26, 2026

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

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
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Apr 26, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 26, 2026

r? @jhpratt

rustbot has assigned @jhpratt.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: libs
  • libs expanded to 6 candidates
  • Random selection from Mark-Simulacrum, jhpratt

@xtqqczze

This comment was marked as outdated.

@DaniPopes
Copy link
Copy Markdown
Contributor Author

No, these are the flags: -Ctarget-cpu=znver3 -Cpanic=abort -Copt-level=3

@jhpratt
Copy link
Copy Markdown
Member

jhpratt commented Apr 28, 2026

Works for me. I'm surprised the compiler doesn't see through it.

@bors r+

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented Apr 28, 2026

📌 Commit 34e1e17 has been approved by jhpratt

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 28, 2026
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
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-bors rust-bors Bot merged commit 8985f1f into rust-lang:main Apr 28, 2026
11 checks passed
@rustbot rustbot added this to the 1.97.0 milestone Apr 28, 2026
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants