unroll first iter of checked_ilog loop to save one multiplication

This commit is contained in:
Trevor Spiteri 2024-04-23 15:49:00 +02:00
parent c67277301c
commit 3b2436c136

View file

@ -1093,9 +1093,12 @@ pub const fn ilog10(self) -> u32 {
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 {