@@ -201,22 +201,14 @@ pub trait Write {
201
201
impl < W : Write + ?Sized > SpecWriteFmt for & mut W {
202
202
#[ inline]
203
203
default fn spec_write_fmt ( mut self , args : Arguments < ' _ > ) -> Result {
204
- if let Some ( s) = args. as_const_str ( ) {
205
- self . write_str ( s)
206
- } else {
207
- write ( & mut self , args)
208
- }
204
+ write ( & mut self , args)
209
205
}
210
206
}
211
207
212
208
impl < W : Write > SpecWriteFmt for & mut W {
213
209
#[ inline]
214
210
fn spec_write_fmt ( self , args : Arguments < ' _ > ) -> Result {
215
- if let Some ( s) = args. as_const_str ( ) {
216
- self . write_str ( s)
217
- } else {
218
- write ( self , args)
219
- }
211
+ write ( self , args)
220
212
}
221
213
}
222
214
@@ -438,15 +430,6 @@ impl<'a> Arguments<'a> {
438
430
_ => None ,
439
431
}
440
432
}
441
-
442
- /// Same as [`Arguments::as_str`], but will only return `Some(s)` if it can be determined at compile time.
443
- #[ must_use]
444
- #[ inline]
445
- fn as_const_str ( & self ) -> Option < & ' static str > {
446
- let s = self . as_str ( ) ;
447
- // SAFETY: both cases are valid as the result
448
- if unsafe { core:: intrinsics:: is_val_statically_known ( s. is_some ( ) ) } { s } else { None }
449
- }
450
433
}
451
434
452
435
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
@@ -1119,8 +1102,14 @@ pub trait UpperExp {
1119
1102
/// ```
1120
1103
///
1121
1104
/// [`write!`]: crate::write!
1105
+ #[ inline]
1122
1106
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1123
1107
pub fn write ( output : & mut dyn Write , args : Arguments < ' _ > ) -> Result {
1108
+ if let Some ( s) = args. as_str ( ) { output. write_str ( s) } else { write_internal ( output, args) }
1109
+ }
1110
+
1111
+ /// Actual implementation of the [`write`], but without the simple string optimization.
1112
+ fn write_internal ( output : & mut dyn Write , args : Arguments < ' _ > ) -> Result {
1124
1113
let mut formatter = Formatter :: new ( output) ;
1125
1114
let mut idx = 0 ;
1126
1115
@@ -1599,9 +1588,8 @@ impl<'a> Formatter<'a> {
1599
1588
/// assert_eq!(format!("{:0>8}", Foo(2)), "Foo 2");
1600
1589
/// ```
1601
1590
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1602
- #[ inline]
1603
1591
pub fn write_fmt ( & mut self , fmt : Arguments < ' _ > ) -> Result {
1604
- if let Some ( s ) = fmt . as_const_str ( ) { self . buf . write_str ( s ) } else { write ( self . buf , fmt) }
1592
+ write ( self . buf , fmt)
1605
1593
}
1606
1594
1607
1595
/// Flags for formatting
@@ -2290,13 +2278,8 @@ impl Write for Formatter<'_> {
2290
2278
self . buf . write_char ( c)
2291
2279
}
2292
2280
2293
- #[ inline]
2294
2281
fn write_fmt ( & mut self , args : Arguments < ' _ > ) -> Result {
2295
- if let Some ( s) = args. as_const_str ( ) {
2296
- self . buf . write_str ( s)
2297
- } else {
2298
- write ( self . buf , args)
2299
- }
2282
+ write ( self . buf , args)
2300
2283
}
2301
2284
}
2302
2285
0 commit comments