File tree 3 files changed +23
-1
lines changed
3 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -3186,6 +3186,16 @@ impl fmt::Write for String {
3186
3186
self . push ( c) ;
3187
3187
Ok ( ( ) )
3188
3188
}
3189
+
3190
+ #[ inline]
3191
+ fn write_fmt ( & mut self , args : fmt:: Arguments < ' _ > ) -> fmt:: Result {
3192
+ if let Some ( s) = args. as_statically_known_str ( ) {
3193
+ self . write_str ( s)
3194
+ } else {
3195
+ self . reserve ( args. estimated_capacity ( ) ) ;
3196
+ fmt:: write ( self , args)
3197
+ }
3198
+ }
3189
3199
}
3190
3200
3191
3201
/// An iterator over the [`char`]s of a string.
Original file line number Diff line number Diff line change @@ -710,9 +710,10 @@ impl<'a> Arguments<'a> {
710
710
}
711
711
712
712
/// Same as [`Arguments::as_str`], but will only return `Some(s)` if it can be determined at compile time.
713
+ #[ unstable( feature = "fmt_internals" , reason = "internal to standard library" , issue = "none" ) ]
713
714
#[ must_use]
714
715
#[ inline]
715
- fn as_statically_known_str ( & self ) -> Option < & ' static str > {
716
+ pub fn as_statically_known_str ( & self ) -> Option < & ' static str > {
716
717
let s = self . as_str ( ) ;
717
718
if core:: intrinsics:: is_val_statically_known ( s. is_some ( ) ) { s } else { None }
718
719
}
Original file line number Diff line number Diff line change @@ -753,10 +753,21 @@ impl Hash for OsString {
753
753
754
754
#[ stable( feature = "os_string_fmt_write" , since = "1.64.0" ) ]
755
755
impl fmt:: Write for OsString {
756
+ #[ inline]
756
757
fn write_str ( & mut self , s : & str ) -> fmt:: Result {
757
758
self . push ( s) ;
758
759
Ok ( ( ) )
759
760
}
761
+
762
+ #[ inline]
763
+ fn write_fmt ( & mut self , args : fmt:: Arguments < ' _ > ) -> fmt:: Result {
764
+ if let Some ( s) = args. as_statically_known_str ( ) {
765
+ self . write_str ( s)
766
+ } else {
767
+ self . reserve ( args. estimated_capacity ( ) ) ;
768
+ fmt:: write ( self , args)
769
+ }
770
+ }
760
771
}
761
772
762
773
impl OsStr {
You can’t perform that action at this time.
0 commit comments