Skip to content

Commit ad38f9b

Browse files
committed
unroll first iter of checked_ilog loop to save one multiplication
1 parent 7a3093a commit ad38f9b

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

core/src/num/uint_macros.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -1093,9 +1093,12 @@ macro_rules! uint_impl {
10931093
pub const fn checked_ilog(self, base: Self) -> Option<u32> {
10941094
if self <= 0 || base <= 1 {
10951095
None
1096+
} else if self < base {
1097+
Some(0)
10961098
} else {
1097-
let mut n = 0;
1098-
let mut r = 1;
1099+
// Since base >= self, n >= 1
1100+
let mut n = 1;
1101+
let mut r = base;
10991102

11001103
// Optimization for 128 bit wide integers.
11011104
if Self::BITS == 128 {

0 commit comments

Comments
 (0)