Auto merge of #108043 - a1phyr:string_write_fmt, r=workingjubilee
Small wins for formatting-related code This PR does two small wins in fmt code: - Override `write_char` for `PadAdapter` to use inner buffer's `write_char` - Override some `write_fmt` implementations to avoid avoid the additional indirection and vtable generated by the default impl.
This commit is contained in:
commit
df99bc151a
1 changed files with 22 additions and 2 deletions
|
@ -188,9 +188,29 @@ pub trait Write {
|
|||
/// assert_eq!(&buf, "world");
|
||||
/// ```
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
fn write_fmt(mut self: &mut Self, args: Arguments<'_>) -> Result {
|
||||
fn write_fmt(&mut self, args: Arguments<'_>) -> Result {
|
||||
// We use a specialization for `Sized` types to avoid an indirection
|
||||
// through `&mut self`
|
||||
trait SpecWriteFmt {
|
||||
fn spec_write_fmt(self, args: Arguments<'_>) -> Result;
|
||||
}
|
||||
|
||||
impl<W: Write + ?Sized> SpecWriteFmt for &mut W {
|
||||
#[inline]
|
||||
default fn spec_write_fmt(mut self, args: Arguments<'_>) -> Result {
|
||||
write(&mut self, args)
|
||||
}
|
||||
}
|
||||
|
||||
impl<W: Write> SpecWriteFmt for &mut W {
|
||||
#[inline]
|
||||
fn spec_write_fmt(self, args: Arguments<'_>) -> Result {
|
||||
write(self, args)
|
||||
}
|
||||
}
|
||||
|
||||
self.spec_write_fmt(args)
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "fmt_write_blanket_impl", since = "1.4.0")]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue