Skip to content

Commit 74cea63

Browse files
authored
Rollup merge of #142764 - ChaiTRex:ilog_10_to_ilog10, r=workingjubilee
Convert `ilog(10)` to `ilog10()` Except in tests, convert `integer.ilog(10)` to `integer.ilog10()` for better speed and to provide better examples of code that efficiently counts decimal digits. I couldn't find any instances of `integer.ilog(2)`.
2 parents 64a7fcf + 88f1ed4 commit 74cea63

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

library/alloc/src/string.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2841,7 +2841,7 @@ macro_rules! impl_to_string {
28412841
impl SpecToString for $signed {
28422842
#[inline]
28432843
fn spec_to_string(&self) -> String {
2844-
const SIZE: usize = $signed::MAX.ilog(10) as usize + 1;
2844+
const SIZE: usize = $signed::MAX.ilog10() as usize + 1;
28452845
let mut buf = [core::mem::MaybeUninit::<u8>::uninit(); SIZE];
28462846
// Only difference between signed and unsigned are these 8 lines.
28472847
let mut out;
@@ -2861,7 +2861,7 @@ macro_rules! impl_to_string {
28612861
impl SpecToString for $unsigned {
28622862
#[inline]
28632863
fn spec_to_string(&self) -> String {
2864-
const SIZE: usize = $unsigned::MAX.ilog(10) as usize + 1;
2864+
const SIZE: usize = $unsigned::MAX.ilog10() as usize + 1;
28652865
let mut buf = [core::mem::MaybeUninit::<u8>::uninit(); SIZE];
28662866

28672867
self._fmt(&mut buf).to_string()

library/core/src/fmt/num.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ macro_rules! impl_Display {
208208
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
209209
#[cfg(not(feature = "optimize_for_size"))]
210210
{
211-
const MAX_DEC_N: usize = $unsigned::MAX.ilog(10) as usize + 1;
211+
const MAX_DEC_N: usize = $unsigned::MAX.ilog10() as usize + 1;
212212
// Buffer decimals for $unsigned with right alignment.
213213
let mut buf = [MaybeUninit::<u8>::uninit(); MAX_DEC_N];
214214

@@ -226,7 +226,7 @@ macro_rules! impl_Display {
226226
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
227227
#[cfg(not(feature = "optimize_for_size"))]
228228
{
229-
const MAX_DEC_N: usize = $unsigned::MAX.ilog(10) as usize + 1;
229+
const MAX_DEC_N: usize = $unsigned::MAX.ilog10() as usize + 1;
230230
// Buffer decimals for $unsigned with right alignment.
231231
let mut buf = [MaybeUninit::<u8>::uninit(); MAX_DEC_N];
232232

@@ -323,7 +323,7 @@ macro_rules! impl_Display {
323323

324324
#[cfg(feature = "optimize_for_size")]
325325
fn $gen_name(mut n: $u, is_nonnegative: bool, f: &mut fmt::Formatter<'_>) -> fmt::Result {
326-
const MAX_DEC_N: usize = $u::MAX.ilog(10) as usize + 1;
326+
const MAX_DEC_N: usize = $u::MAX.ilog10() as usize + 1;
327327
let mut buf = [MaybeUninit::<u8>::uninit(); MAX_DEC_N];
328328
let mut curr = MAX_DEC_N;
329329
let buf_ptr = MaybeUninit::slice_as_mut_ptr(&mut buf);
@@ -565,7 +565,7 @@ mod imp {
565565
}
566566
impl_Exp!(i128, u128 as u128 via to_u128 named exp_u128);
567567

568-
const U128_MAX_DEC_N: usize = u128::MAX.ilog(10) as usize + 1;
568+
const U128_MAX_DEC_N: usize = u128::MAX.ilog10() as usize + 1;
569569

570570
#[stable(feature = "rust1", since = "1.0.0")]
571571
impl fmt::Display for u128 {

src/librustdoc/html/sources.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ pub(crate) fn print_src(
353353
);
354354
Ok(())
355355
});
356-
let max_nb_digits = if lines > 0 { lines.ilog(10) + 1 } else { 1 };
356+
let max_nb_digits = if lines > 0 { lines.ilog10() + 1 } else { 1 };
357357
match source_context {
358358
SourceContext::Standalone { file_path } => Source {
359359
code_html: code,

0 commit comments

Comments
 (0)