Optimize std::str::Chars::next and std::str::Chars::next_back by Kmeakin · Pull Request #142038 · rust-lang/rust (original) (raw)
Conversation
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
[ Show hidden characters]({{ revealButtonHref }})
rustbot added S-waiting-on-review
Status: Awaiting review from the assignee but also interested parties.
Relevant to the library team, which will review and decide on the PR/issue.
labels
rustbot added S-waiting-on-author
Status: This is awaiting some action (such as code changes or more information) from the author.
and removed S-waiting-on-review
Status: Awaiting review from the assignee but also interested parties.
labels
rustbot added S-waiting-on-review
Status: Awaiting review from the assignee but also interested parties.
and removed S-waiting-on-author
Status: This is awaiting some action (such as code changes or more information) from the author.
labels
Comment on lines 29 to 37
rustbot added S-waiting-on-author
Status: This is awaiting some action (such as code changes or more information) from the author.
and removed S-waiting-on-review
Status: Awaiting review from the assignee but also interested parties.
labels
rust-bors bot added a commit that referenced this pull request
Optimize std::str::Chars::next and std::str::Chars::next_back
There are only 0x10FFFF possible codepoints, so we can exhaustively test all of them.
By reordering some operations, we can expose some opportunites for
CSE. Also convert the series of nested if branches to early return,
which IMO makes the code clearer.
Comparison of assembly before and after for next_code_point:
https://godbolt.org/z/9Te84YzhK
Comparison of assembly before and after for next_code_point_reverse:
https://godbolt.org/z/fTx1a7oz1