Skip to content
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

Fix suspicious_xor_used_as_pow.rs performance #11255

Merged
merged 1 commit into from
Aug 3, 2023

Conversation

blyxyas
Copy link
Member

@blyxyas blyxyas commented Jul 29, 2023

The original suspicious_xor_used_as_pow lint had poor performance, so I fixed that + a little refactor so that module is readable.

107 millis. -> 106 millis. Using SPEEDTEST on Rust's VMs

fix #11060
changelog: [suspicious_xor_used_as_pow]: Improve performance by 0.934%

@rustbot
Copy link
Collaborator

rustbot commented Jul 29, 2023

r? @xFrednet

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Jul 29, 2023
@blyxyas blyxyas force-pushed the fix-perf-sus_xor_used_as_pow branch from c5d685d to 7a8b9ab Compare July 29, 2023 18:51
Copy link
Member

@xFrednet xFrednet left a comment

Choose a reason for hiding this comment

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

Looks good to me, just two tiny nits and a question. If the question is interional, you can also r=me afterwards :)

btw, sorry that the review took so long. I'm currently visiting my hometown, and I was at a festival last weekend. I spent less time on open source than usual, which means it's probably at a normal/healthy level right now ^^.

Comment on lines 49 to 50
format!("{}.pow({})", lit_left
.node, lit_right.node),
Copy link
Member

Choose a reason for hiding this comment

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

NIT: This format is a little weird. rustfmt sadly doesn't work in functions that have if-let chains in them. Can you fix this?

);
matches!(lit_right.node, LitKind::Int(..) | LitKind::Float(..)) &&
matches!(lit_left.node, LitKind::Int(..) | LitKind::Float(..)) &&
NumericLiteral::from_lit_kind(&snippet(cx, lit_right.span, ".."), &lit_right.node).is_some_and(|x| x.is_decimal())
Copy link
Member

Choose a reason for hiding this comment

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

Is it intentional, that you only check the is_decimal for one of the nodes?

Copy link
Member Author

Choose a reason for hiding this comment

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

I kinda feel like it's intentional. It doesn't really make sense to check if the left value is decimal, as in mathematical notation the ^ symbol speaks more about the right value than the left.

@@ -34,21 +36,20 @@ impl LateLintPass<'_> for ConfusingXorAndPow {
left.span.ctxt() == right.span.ctxt() &&
Copy link
Member

Choose a reason for hiding this comment

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

Since this was your first lint, I'll also be a bit more nitpicky 😉

Can you fix the formatting, to have the && before the condition and not at the end of the line and also remove the tab character in line 34?

@blyxyas blyxyas force-pushed the fix-perf-sus_xor_used_as_pow branch from 2f8e879 to b8fba79 Compare August 3, 2023 19:58
@blyxyas blyxyas force-pushed the fix-perf-sus_xor_used_as_pow branch from b8fba79 to 3fb8441 Compare August 3, 2023 19:59
@blyxyas
Copy link
Member Author

blyxyas commented Aug 3, 2023

@bors r=xFrednet

@bors
Copy link
Collaborator

bors commented Aug 3, 2023

📌 Commit 3fb8441 has been approved by xFrednet

It is now in the queue for this repository.

@bors
Copy link
Collaborator

bors commented Aug 3, 2023

⌛ Testing commit 3fb8441 with merge 5818225...

@bors
Copy link
Collaborator

bors commented Aug 3, 2023

☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test
Approved by: xFrednet
Pushing 5818225 to master...

@bors bors merged commit 5818225 into rust-lang:master Aug 3, 2023
5 checks passed
@blyxyas blyxyas deleted the fix-perf-sus_xor_used_as_pow branch October 5, 2023 09:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Small: Optimize suspicious_xor_used_as_pow
4 participants