Commit 09bfbad
committed
Auto merge of #121001 - nyurik:optimize-core-fmt, r=<try>
perf: improve write_fmt to handle simple strings
Per `@dtolnay` suggestion in serde-rs/serde#2697 (comment) - attempt to speed up performance in the cases of a simple string format without arguments:
```rust
write!(f, "text") -> f.write_str("text")
```
```diff
+ #[inline]
pub fn write_fmt(&mut self, f: fmt::Arguments) -> fmt::Result {
+ if let Some(s) = f.as_str() {
+ self.buf.write_str(s)
+ } else {
write(self.buf, f)
+ }
}
```
Hopefully it will improve the simple case for the #99012
CC: `@m-ou-se` as probably the biggest expert in everything `format!`1 file changed
+6
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
201 | 201 | | |
202 | 202 | | |
203 | 203 | | |
204 | | - | |
| 204 | + | |
205 | 205 | | |
206 | 206 | | |
207 | 207 | | |
208 | 208 | | |
209 | 209 | | |
210 | 210 | | |
211 | | - | |
| 211 | + | |
212 | 212 | | |
213 | 213 | | |
214 | 214 | | |
| |||
1582 | 1582 | | |
1583 | 1583 | | |
1584 | 1584 | | |
| 1585 | + | |
1585 | 1586 | | |
1586 | | - | |
| 1587 | + | |
1587 | 1588 | | |
1588 | 1589 | | |
1589 | 1590 | | |
| |||
2272 | 2273 | | |
2273 | 2274 | | |
2274 | 2275 | | |
| 2276 | + | |
2275 | 2277 | | |
2276 | | - | |
| 2278 | + | |
2277 | 2279 | | |
2278 | 2280 | | |
2279 | 2281 | | |
| |||
0 commit comments