Fix inlining issue for non-const case
This commit is contained in:
parent
6fa7d6ca16
commit
c50779fc78
2 changed files with 20 additions and 12 deletions
|
|
@ -201,14 +201,22 @@ pub trait Write {
|
|||
impl<W: Write + ?Sized> SpecWriteFmt for &mut W {
|
||||
#[inline]
|
||||
default fn spec_write_fmt(mut self, args: Arguments<'_>) -> Result {
|
||||
if let Some(s) = args.as_str() { self.write_str(s) } else { write(&mut self, args) }
|
||||
if let Some(s) = args.as_const_str() {
|
||||
self.write_str(s)
|
||||
} else {
|
||||
write(&mut self, args)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<W: Write> SpecWriteFmt for &mut W {
|
||||
#[inline]
|
||||
fn spec_write_fmt(self, args: Arguments<'_>) -> Result {
|
||||
if let Some(s) = args.as_str() { self.write_str(s) } else { write(self, args) }
|
||||
if let Some(s) = args.as_const_str() {
|
||||
self.write_str(s)
|
||||
} else {
|
||||
write(self, args)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -431,17 +439,12 @@ impl<'a> Arguments<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Same as `as_str`, but will only return a `Some` value if it can be determined at compile time.
|
||||
/// Same as [`Arguments::as_str`], but will only return `Some(s)` if it can be determined at compile time.
|
||||
#[must_use]
|
||||
#[inline]
|
||||
const fn as_const_str(&self) -> Option<&'static str> {
|
||||
let s = self.as_str();
|
||||
// if unsafe { core::intrinsics::is_val_statically_known(matches!((self.pieces, self.args), ([], []) | ([_], []))) } {
|
||||
if unsafe { core::intrinsics::is_val_statically_known(s) } {
|
||||
s
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
||||
if unsafe { core::intrinsics::is_val_statically_known(s.is_some()) } { s } else { None }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1597,7 +1600,7 @@ impl<'a> Formatter<'a> {
|
|||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn write_fmt(&mut self, fmt: Arguments<'_>) -> Result {
|
||||
if let Some(s) = fmt.as_str() { self.buf.write_str(s) } else { write(self.buf, fmt) }
|
||||
if let Some(s) = fmt.as_const_str() { self.buf.write_str(s) } else { write(self.buf, fmt) }
|
||||
}
|
||||
|
||||
/// Flags for formatting
|
||||
|
|
@ -2288,7 +2291,11 @@ impl Write for Formatter<'_> {
|
|||
|
||||
#[inline]
|
||||
fn write_fmt(&mut self, args: Arguments<'_>) -> Result {
|
||||
if let Some(s) = args.as_str() { self.buf.write_str(s) } else { write(self.buf, args) }
|
||||
if let Some(s) = args.as_const_str() {
|
||||
self.buf.write_str(s)
|
||||
} else {
|
||||
write(self.buf, args)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -176,6 +176,7 @@
|
|||
#![feature(ip)]
|
||||
#![feature(ip_bits)]
|
||||
#![feature(is_ascii_octdigit)]
|
||||
#![feature(is_val_statically_known)]
|
||||
#![feature(isqrt)]
|
||||
#![feature(maybe_uninit_uninit_array)]
|
||||
#![feature(non_null_convenience)]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue