mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-29 03:27:44 +00:00
Use non-generic inner function for pointer formatting
This commit is contained in:
parent
454cc5fb86
commit
37c8f254ed
@ -2186,28 +2186,34 @@ impl Display for char {
|
|||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
impl<T: ?Sized> Pointer for *const T {
|
impl<T: ?Sized> Pointer for *const T {
|
||||||
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
|
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
|
||||||
let old_width = f.width;
|
/// Since the formatting will be identical for all pointer types, use a non-monomorphized
|
||||||
let old_flags = f.flags;
|
/// implementation for the actual formatting to reduce the amount of codegen work needed
|
||||||
|
fn inner(ptr: *const (), f: &mut Formatter<'_>) -> Result {
|
||||||
|
let old_width = f.width;
|
||||||
|
let old_flags = f.flags;
|
||||||
|
|
||||||
// The alternate flag is already treated by LowerHex as being special-
|
// The alternate flag is already treated by LowerHex as being special-
|
||||||
// it denotes whether to prefix with 0x. We use it to work out whether
|
// it denotes whether to prefix with 0x. We use it to work out whether
|
||||||
// or not to zero extend, and then unconditionally set it to get the
|
// or not to zero extend, and then unconditionally set it to get the
|
||||||
// prefix.
|
// prefix.
|
||||||
if f.alternate() {
|
if f.alternate() {
|
||||||
f.flags |= 1 << (FlagV1::SignAwareZeroPad as u32);
|
f.flags |= 1 << (FlagV1::SignAwareZeroPad as u32);
|
||||||
|
|
||||||
if f.width.is_none() {
|
if f.width.is_none() {
|
||||||
f.width = Some((usize::BITS / 4) as usize + 2);
|
f.width = Some((usize::BITS / 4) as usize + 2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
f.flags |= 1 << (FlagV1::Alternate as u32);
|
||||||
|
|
||||||
|
let ret = LowerHex::fmt(&(ptr as usize), f);
|
||||||
|
|
||||||
|
f.width = old_width;
|
||||||
|
f.flags = old_flags;
|
||||||
|
|
||||||
|
ret
|
||||||
}
|
}
|
||||||
f.flags |= 1 << (FlagV1::Alternate as u32);
|
|
||||||
|
|
||||||
let ret = LowerHex::fmt(&(*self as *const () as usize), f);
|
inner(*self as *const (), f)
|
||||||
|
|
||||||
f.width = old_width;
|
|
||||||
f.flags = old_flags;
|
|
||||||
|
|
||||||
ret
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user