Skip to content

Commit

Permalink
checked_ilog: improve performance
Browse files Browse the repository at this point in the history
  • Loading branch information
FedericoStra committed Sep 17, 2023
1 parent 8ed1d4a commit 00035b5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions library/core/src/num/int_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2477,18 +2477,18 @@ macro_rules! int_impl {
None
} else {
let mut n = 0;
let mut r = self;
let mut r = 1;

// Optimization for 128 bit wide integers.
if Self::BITS == 128 {
let b = Self::ilog2(self) / (Self::ilog2(base) + 1);
n += b;
r /= base.pow(b as u32);
r *= base.pow(b);
}

while r >= base {
r /= base;
while r <= self / base {
n += 1;
r *= base;
}
Some(n)
}
Expand Down
8 changes: 4 additions & 4 deletions library/core/src/num/uint_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -810,18 +810,18 @@ macro_rules! uint_impl {
None
} else {
let mut n = 0;
let mut r = self;
let mut r = 1;

// Optimization for 128 bit wide integers.
if Self::BITS == 128 {
let b = Self::ilog2(self) / (Self::ilog2(base) + 1);
n += b;
r /= base.pow(b as u32);
r *= base.pow(b);
}

while r >= base {
r /= base;
while r <= self / base {
n += 1;
r *= base;
}
Some(n)
}
Expand Down

0 comments on commit 00035b5

Please sign in to comment.