Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions library/core/src/num/uint_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1491,6 +1491,20 @@ macro_rules! uint_impl {
without modifying the original"]
#[inline]
pub const fn checked_ilog(self, base: Self) -> Option<u32> {
// Inform compiler of optimizations when the base is known at
// compile time and there's a cheaper method available.
//
// Note: Like all optimizations, this is not guaranteed to be
// applied by the compiler. If you want those specific bases,
// use `.checked_ilog2()` or `.checked_ilog10()` directly.
if core::intrinsics::is_val_statically_known(base) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great use for this intrinsic! Nice.

if base == 2 {
return self.checked_ilog2();
} else if base == 10 {
return self.checked_ilog10();
}
}

if self <= 0 || base <= 1 {
None
} else if self < base {
Expand Down
Loading