Skip to content

Commit 9147a36

Browse files
committed
perf(manual_is_power_of_two): perform the is_integer_literal check first
.. as it's much cheaper than `count_ones_receiver`
1 parent dddaf07 commit 9147a36

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

clippy_lints/src/manual_is_power_of_two.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,12 @@ impl<'tcx> LateLintPass<'tcx> for ManualIsPowerOfTwo {
7070
if !expr.span.from_expansion()
7171
&& let Some((lhs, rhs)) = unexpanded_binop_operands(expr, BinOpKind::Eq)
7272
{
73-
if let Some(a) = count_ones_receiver(cx, lhs)
74-
&& is_integer_literal(rhs, 1)
73+
if is_integer_literal(rhs, 1)
74+
&& let Some(a) = count_ones_receiver(cx, lhs)
7575
{
7676
self.build_sugg(cx, expr, a);
77-
} else if let Some(a) = count_ones_receiver(cx, rhs)
78-
&& is_integer_literal(lhs, 1)
77+
} else if is_integer_literal(lhs, 1)
78+
&& let Some(a) = count_ones_receiver(cx, rhs)
7979
{
8080
self.build_sugg(cx, expr, a);
8181
} else if is_integer_literal(rhs, 0)

0 commit comments

Comments
 (0)