Use non-generic inner function for pointer formatting

This commit is contained in:
jam1garner 2021-11-26 13:59:57 -05:00
parent 454cc5fb86
commit 37c8f254ed

View File

@ -2186,6 +2186,9 @@ fn fmt(&self, f: &mut Formatter<'_>) -> Result {
#[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 {
/// Since the formatting will be identical for all pointer types, use a non-monomorphized
/// 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_width = f.width;
let old_flags = f.flags; let old_flags = f.flags;
@ -2202,13 +2205,16 @@ fn fmt(&self, f: &mut Formatter<'_>) -> Result {
} }
f.flags |= 1 << (FlagV1::Alternate as u32); f.flags |= 1 << (FlagV1::Alternate as u32);
let ret = LowerHex::fmt(&(*self as *const () as usize), f); let ret = LowerHex::fmt(&(ptr as usize), f);
f.width = old_width; f.width = old_width;
f.flags = old_flags; f.flags = old_flags;
ret ret
} }
inner(*self as *const (), f)
}
} }
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]