@@ -166,6 +166,7 @@ pub trait Write {
166
166
/// assert_eq!(&buf, "ab");
167
167
/// ```
168
168
#[ stable( feature = "fmt_write_char" , since = "1.1.0" ) ]
169
+ #[ inline]
169
170
fn write_char ( & mut self , c : char ) -> Result {
170
171
self . write_str ( c. encode_utf8 ( & mut [ 0 ; 4 ] ) )
171
172
}
@@ -189,21 +190,25 @@ pub trait Write {
189
190
/// assert_eq!(&buf, "world");
190
191
/// ```
191
192
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
193
+ #[ inline]
192
194
fn write_fmt ( mut self : & mut Self , args : Arguments < ' _ > ) -> Result {
193
195
write ( & mut self , args)
194
196
}
195
197
}
196
198
197
199
#[ stable( feature = "fmt_write_blanket_impl" , since = "1.4.0" ) ]
198
200
impl < W : Write + ?Sized > Write for & mut W {
201
+ #[ inline]
199
202
fn write_str ( & mut self , s : & str ) -> Result {
200
203
( * * self ) . write_str ( s)
201
204
}
202
205
206
+ #[ inline]
203
207
fn write_char ( & mut self , c : char ) -> Result {
204
208
( * * self ) . write_char ( c)
205
209
}
206
210
211
+ #[ inline]
207
212
fn write_fmt ( & mut self , args : Arguments < ' _ > ) -> Result {
208
213
( * * self ) . write_fmt ( args)
209
214
}
@@ -240,6 +245,7 @@ impl<'a> Formatter<'a> {
240
245
/// Currently not intended for use outside of the standard library.
241
246
#[ unstable( feature = "fmt_internals" , reason = "internal to standard library" , issue = "none" ) ]
242
247
#[ doc( hidden) ]
248
+ #[ inline]
243
249
pub fn new ( buf : & ' a mut ( dyn Write + ' a ) ) -> Formatter < ' a > {
244
250
Formatter {
245
251
flags : 0 ,
@@ -1277,6 +1283,7 @@ pub trait UpperExp {
1277
1283
/// [`write!`]: crate::write!
1278
1284
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1279
1285
#[ cfg( not( bootstrap) ) ]
1286
+ #[ inline]
1280
1287
pub fn write ( output : & mut dyn Write , args : Arguments < ' _ > ) -> Result {
1281
1288
match args. inner {
1282
1289
Inner :: Fn ( f) => f ( & mut Formatter :: new ( output) ) ,
@@ -1549,11 +1556,17 @@ impl<'a> Formatter<'a> {
1549
1556
/// assert_eq!(&format!("{Foo:0>4}"), "0Foo");
1550
1557
/// ```
1551
1558
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1559
+ #[ inline]
1552
1560
pub fn pad ( & mut self , s : & str ) -> Result {
1553
1561
// Make sure there's a fast path up front
1554
1562
if self . width . is_none ( ) && self . precision . is_none ( ) {
1555
- return self . buf . write_str ( s) ;
1563
+ self . buf . write_str ( s)
1564
+ } else {
1565
+ self . pad_slow ( s)
1556
1566
}
1567
+ }
1568
+
1569
+ fn pad_slow ( & mut self , s : & str ) -> Result {
1557
1570
// The `precision` field can be interpreted as a `max-width` for the
1558
1571
// string being formatted.
1559
1572
let s = if let Some ( max) = self . precision {
@@ -1733,6 +1746,7 @@ impl<'a> Formatter<'a> {
1733
1746
/// assert_eq!(&format!("{Foo:0>8}"), "Foo");
1734
1747
/// ```
1735
1748
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1749
+ #[ inline]
1736
1750
pub fn write_str ( & mut self , data : & str ) -> Result {
1737
1751
self . buf . write_str ( data)
1738
1752
}
@@ -1756,6 +1770,7 @@ impl<'a> Formatter<'a> {
1756
1770
/// assert_eq!(&format!("{:0>8}", Foo(2)), "Foo 2");
1757
1771
/// ```
1758
1772
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1773
+ #[ inline]
1759
1774
pub fn write_fmt ( & mut self , fmt : Arguments < ' _ > ) -> Result {
1760
1775
write ( self . buf , fmt)
1761
1776
}
@@ -1768,6 +1783,7 @@ impl<'a> Formatter<'a> {
1768
1783
note = "use the `sign_plus`, `sign_minus`, `alternate`, \
1769
1784
or `sign_aware_zero_pad` methods instead"
1770
1785
) ]
1786
+ #[ inline]
1771
1787
pub fn flags ( & self ) -> u32 {
1772
1788
self . flags
1773
1789
}
@@ -1801,6 +1817,7 @@ impl<'a> Formatter<'a> {
1801
1817
/// ```
1802
1818
#[ must_use]
1803
1819
#[ stable( feature = "fmt_flags" , since = "1.5.0" ) ]
1820
+ #[ inline]
1804
1821
pub fn fill ( & self ) -> char {
1805
1822
self . fill
1806
1823
}
@@ -1838,6 +1855,7 @@ impl<'a> Formatter<'a> {
1838
1855
/// ```
1839
1856
#[ must_use]
1840
1857
#[ stable( feature = "fmt_flags_align" , since = "1.28.0" ) ]
1858
+ #[ inline]
1841
1859
pub fn align ( & self ) -> Option < Alignment > {
1842
1860
match self . align {
1843
1861
rt:: v1:: Alignment :: Left => Some ( Alignment :: Left ) ,
@@ -1873,6 +1891,7 @@ impl<'a> Formatter<'a> {
1873
1891
/// ```
1874
1892
#[ must_use]
1875
1893
#[ stable( feature = "fmt_flags" , since = "1.5.0" ) ]
1894
+ #[ inline]
1876
1895
pub fn width ( & self ) -> Option < usize > {
1877
1896
self . width
1878
1897
}
@@ -1904,6 +1923,7 @@ impl<'a> Formatter<'a> {
1904
1923
/// ```
1905
1924
#[ must_use]
1906
1925
#[ stable( feature = "fmt_flags" , since = "1.5.0" ) ]
1926
+ #[ inline]
1907
1927
pub fn precision ( & self ) -> Option < usize > {
1908
1928
self . precision
1909
1929
}
@@ -1936,6 +1956,7 @@ impl<'a> Formatter<'a> {
1936
1956
/// ```
1937
1957
#[ must_use]
1938
1958
#[ stable( feature = "fmt_flags" , since = "1.5.0" ) ]
1959
+ #[ inline]
1939
1960
pub fn sign_plus ( & self ) -> bool {
1940
1961
self . flags & ( 1 << FlagV1 :: SignPlus as u32 ) != 0
1941
1962
}
@@ -1965,6 +1986,7 @@ impl<'a> Formatter<'a> {
1965
1986
/// ```
1966
1987
#[ must_use]
1967
1988
#[ stable( feature = "fmt_flags" , since = "1.5.0" ) ]
1989
+ #[ inline]
1968
1990
pub fn sign_minus ( & self ) -> bool {
1969
1991
self . flags & ( 1 << FlagV1 :: SignMinus as u32 ) != 0
1970
1992
}
@@ -1993,6 +2015,7 @@ impl<'a> Formatter<'a> {
1993
2015
/// ```
1994
2016
#[ must_use]
1995
2017
#[ stable( feature = "fmt_flags" , since = "1.5.0" ) ]
2018
+ #[ inline]
1996
2019
pub fn alternate ( & self ) -> bool {
1997
2020
self . flags & ( 1 << FlagV1 :: Alternate as u32 ) != 0
1998
2021
}
@@ -2019,6 +2042,7 @@ impl<'a> Formatter<'a> {
2019
2042
/// ```
2020
2043
#[ must_use]
2021
2044
#[ stable( feature = "fmt_flags" , since = "1.5.0" ) ]
2045
+ #[ inline]
2022
2046
pub fn sign_aware_zero_pad ( & self ) -> bool {
2023
2047
self . flags & ( 1 << FlagV1 :: SignAwareZeroPad as u32 ) != 0
2024
2048
}
@@ -2440,14 +2464,17 @@ impl<'a> Formatter<'a> {
2440
2464
2441
2465
#[ stable( since = "1.2.0" , feature = "formatter_write" ) ]
2442
2466
impl Write for Formatter < ' _ > {
2467
+ #[ inline]
2443
2468
fn write_str ( & mut self , s : & str ) -> Result {
2444
2469
self . buf . write_str ( s)
2445
2470
}
2446
2471
2472
+ #[ inline]
2447
2473
fn write_char ( & mut self , c : char ) -> Result {
2448
2474
self . buf . write_char ( c)
2449
2475
}
2450
2476
2477
+ #[ inline]
2451
2478
fn write_fmt ( & mut self , args : Arguments < ' _ > ) -> Result {
2452
2479
write ( self . buf , args)
2453
2480
}
@@ -2535,6 +2562,7 @@ impl Debug for str {
2535
2562
2536
2563
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
2537
2564
impl Display for str {
2565
+ #[ inline]
2538
2566
fn fmt ( & self , f : & mut Formatter < ' _ > ) -> Result {
2539
2567
f. pad ( self )
2540
2568
}
0 commit comments