Skip to content

Commit bbe500a

Browse files
Rollup merge of #158448 - GuillaumeGomez:cleanup-numbuffer, r=Amanieu
Cleanup `NumBuffer` comment and replace `ilog(10)` with `ilog10()` A [nice person from mastodon](https://toot.cat/@jamey/116815991086205506) pointed out that a `FIXME` comment should have been removed alongside the others in #157976, and also pointed out that the documentation mentions that `ilog10` is more optimized than `ilog(10)`. Shouldn't matter much here but since I already made a PR to remove the FIXME comment... r? @Amanieu
2 parents 171acfa + eb78d13 commit bbe500a

2 files changed

Lines changed: 5 additions & 6 deletions

File tree

library/core/src/fmt/num.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ macro_rules! impl_Display {
361361

362362
#[cfg(feature = "optimize_for_size")]
363363
fn ${concat($fmt_fn, _small)}(n: $T, is_nonnegative: bool, f: &mut fmt::Formatter<'_>) -> fmt::Result {
364-
const MAX_DEC_N: usize = $T::MAX.ilog(10) as usize + 1;
364+
const MAX_DEC_N: usize = $T::MAX.ilog10() as usize + 1;
365365
let mut buf = [MaybeUninit::<u8>::uninit(); MAX_DEC_N];
366366

367367
let offset = ${concat($fmt_fn, _in_buf_small)}(n, &mut buf);

library/core/src/fmt/num_buffer.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ macro_rules! impl_NumBufferTrait {
1717
#[stable(feature = "int_format_into", since = "CURRENT_RUSTC_VERSION")]
1818
impl NumBufferTrait for $signed {
1919
// `+ 2` and not `+ 1` to include the `-` character.
20-
const DEFAULT: Self::Buf = [MaybeUninit::<u8>::uninit(); $signed::MAX.ilog(10) as usize + 2];
21-
type Buf = [MaybeUninit<u8>; $signed::MAX.ilog(10) as usize + 2];
20+
const DEFAULT: Self::Buf = [MaybeUninit::<u8>::uninit(); $signed::MAX.ilog10() as usize + 2];
21+
type Buf = [MaybeUninit<u8>; $signed::MAX.ilog10() as usize + 2];
2222
}
2323
#[stable(feature = "int_format_into", since = "CURRENT_RUSTC_VERSION")]
2424
impl NumBufferTrait for $unsigned {
25-
const DEFAULT: Self::Buf = [MaybeUninit::<u8>::uninit(); $unsigned::MAX.ilog(10) as usize + 1];
26-
type Buf = [MaybeUninit<u8>; $unsigned::MAX.ilog(10) as usize + 1];
25+
const DEFAULT: Self::Buf = [MaybeUninit::<u8>::uninit(); $unsigned::MAX.ilog10() as usize + 1];
26+
type Buf = [MaybeUninit<u8>; $unsigned::MAX.ilog10() as usize + 1];
2727
}
2828
)*
2929
}
@@ -74,7 +74,6 @@ impl<T: NumBufferTrait> NumBuffer<T> {
7474
#[stable(feature = "int_format_into", since = "CURRENT_RUSTC_VERSION")]
7575
#[rustc_const_stable(feature = "int_format_into", since = "CURRENT_RUSTC_VERSION")]
7676
pub const fn new() -> Self {
77-
// FIXME: Once const generics feature is working, use `T::BUF_SIZE` instead of 40.
7877
NumBuffer { buf: T::DEFAULT, phantom: core::marker::PhantomData }
7978
}
8079
}

0 commit comments

Comments
 (0)