Skip to content

rustc_mir: calc hex number length without string allocation #86304

New 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

Merged
merged 1 commit into from
Jul 1, 2021

Conversation

klensy
Copy link
Contributor

@klensy klensy commented Jun 14, 2021

No description provided.

@rust-highfive
Copy link
Contributor

r? @jackh726

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 14, 2021
Comment on lines 1029 to 1034
/// ```ignore
/// assert_eq!(1, hex_number_length(0));
/// assert_eq!(1, hex_number_length(1));
/// assert_eq!(2, hex_number_length(16));
/// ```
fn hex_number_length(x: u64) -> usize {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Idk how to write doctest for private function :-(

@rust-log-analyzer

This comment has been minimized.

@klensy
Copy link
Contributor Author

klensy commented Jun 20, 2021

Bump

Copy link
Member

@jackh726 jackh726 left a comment

Choose a reason for hiding this comment

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

I'm 🤷‍♀️ about this. I'll do a perf run, but I imagine we probably don't see a difference. Cleanup-wise, I guess it's slightly nicer.

/// assert_eq!(2, hex_number_length(16));
/// ```
fn hex_number_length(x: u64) -> usize {
let mut length = if x == 0 { 1 } else { 0 };
Copy link
Member

Choose a reason for hiding this comment

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

if x ==0, why not just early return 1?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When i wrote this i remember that this will give the same asm, but i'll recheck.

Copy link
Member

Choose a reason for hiding this comment

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

Returning early is more clear to me

@jackh726
Copy link
Member

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

@bors
Copy link
Collaborator

bors commented Jun 24, 2021

⌛ Trying commit 723293c4f6ced9d10f3c29083de866573b3caa31 with merge 812cf9a5f9dc29d03e0210b7a827600d2c30bdbb...

@klensy
Copy link
Contributor Author

klensy commented Jun 24, 2021

@jackh726 Yeah, i don't expect perf gains, but if we have opportunity not to use allocations, we can do it (plus, this code not so hard to read, i think).

@bors
Copy link
Collaborator

bors commented Jun 24, 2021

☀️ Try build successful - checks-actions
Build commit: 812cf9a5f9dc29d03e0210b7a827600d2c30bdbb (812cf9a5f9dc29d03e0210b7a827600d2c30bdbb)

@rust-timer
Copy link
Collaborator

Queued 812cf9a5f9dc29d03e0210b7a827600d2c30bdbb with parent 456a032, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking try commit (812cf9a5f9dc29d03e0210b7a827600d2c30bdbb): comparison url.

Summary: ERROR categorizing benchmark run!

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. Please note that if the perf results are neutral, you should likely undo the rollup=never given below by specifying rollup- to bors.

Importantly, though, if the results of this run are non-neutral do not roll this PR up -- it will mask other regressions or improvements in the roll up.

@bors rollup=never
@rustbot label: +S-waiting-on-review -S-waiting-on-perf -perf-regression

@klensy
Copy link
Contributor Author

klensy commented Jun 26, 2021

This run looks broken - no result info.

@jackh726
Copy link
Member

@bors try @rust-timer queue

take 2

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jun 26, 2021
@bors
Copy link
Collaborator

bors commented Jun 26, 2021

⌛ Trying commit 723293c4f6ced9d10f3c29083de866573b3caa31 with merge 4c85d7041c65d68b8ee108c4e58a805ea36dac39...

@bors
Copy link
Collaborator

bors commented Jun 26, 2021

☀️ Try build successful - checks-actions
Build commit: 4c85d7041c65d68b8ee108c4e58a805ea36dac39 (4c85d7041c65d68b8ee108c4e58a805ea36dac39)

@rust-timer
Copy link
Collaborator

Queued 4c85d7041c65d68b8ee108c4e58a805ea36dac39 with parent f2571a2, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking try commit (4c85d7041c65d68b8ee108c4e58a805ea36dac39): comparison url.

Summary: This benchmark run did not return any significant changes.

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. Please note that if the perf results are neutral, you should likely undo the rollup=never given below by specifying rollup- to bors.

Importantly, though, if the results of this run are non-neutral do not roll this PR up -- it will mask other regressions or improvements in the roll up.

@bors rollup=never
@rustbot label: +S-waiting-on-review -S-waiting-on-perf -perf-regression

@rustbot
Copy link
Collaborator

rustbot commented Jun 26, 2021

Error: Label perf-regression can only be set by Rust team members

Please let @rust-lang/release know if you're having trouble with this bot.

@JohnTitor JohnTitor removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jun 28, 2021
@jackh726
Copy link
Member

r=me after modifying hex_number_length to return early on x == 0

@jackh726 jackh726 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 Jun 30, 2021
@jackh726
Copy link
Member

jackh726 commented Jul 1, 2021

@bors r+

@bors
Copy link
Collaborator

bors commented Jul 1, 2021

📌 Commit 2b57fc4 has been approved by jackh726

@bors bors 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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jul 1, 2021
@bors
Copy link
Collaborator

bors commented Jul 1, 2021

⌛ Testing commit 2b57fc4 with merge ecef52a...

@bors
Copy link
Collaborator

bors commented Jul 1, 2021

☀️ Test successful - checks-actions
Approved by: jackh726
Pushing ecef52a to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jul 1, 2021
@bors bors merged commit ecef52a into rust-lang:master Jul 1, 2021
@rustbot rustbot added this to the 1.55.0 milestone Jul 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants