Skip to content

Commit 666d26f

Browse files
committed
checked_ilog: set n and r directly avoiding arithmetic operations
1 parent 00035b5 commit 666d26f

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

library/core/src/num/int_macros.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -2481,9 +2481,8 @@ macro_rules! int_impl {
24812481

24822482
// Optimization for 128 bit wide integers.
24832483
if Self::BITS == 128 {
2484-
let b = Self::ilog2(self) / (Self::ilog2(base) + 1);
2485-
n += b;
2486-
r *= base.pow(b);
2484+
n = self.ilog2() / (base.ilog2() + 1);
2485+
r = base.pow(n);
24872486
}
24882487

24892488
while r <= self / base {

library/core/src/num/uint_macros.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -814,9 +814,8 @@ macro_rules! uint_impl {
814814

815815
// Optimization for 128 bit wide integers.
816816
if Self::BITS == 128 {
817-
let b = Self::ilog2(self) / (Self::ilog2(base) + 1);
818-
n += b;
819-
r *= base.pow(b);
817+
n = self.ilog2() / (base.ilog2() + 1);
818+
r = base.pow(n);
820819
}
821820

822821
while r <= self / base {

0 commit comments

Comments
 (0)