Skip to content

Commit

Permalink
unroll first iter of checked_ilog loop to save one multiplication
Browse files Browse the repository at this point in the history
  • Loading branch information
tspiteri committed Apr 23, 2024
1 parent 7a3093a commit ad38f9b
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions core/src/num/uint_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1093,9 +1093,12 @@ macro_rules! uint_impl {
pub const fn checked_ilog(self, base: Self) -> Option<u32> {
if self <= 0 || base <= 1 {
None
} else if self < base {
Some(0)
} else {
let mut n = 0;
let mut r = 1;
// Since base >= self, n >= 1
let mut n = 1;
let mut r = base;

// Optimization for 128 bit wide integers.
if Self::BITS == 128 {
Expand Down

0 comments on commit ad38f9b

Please sign in to comment.