diff options
| author | bors <bors@rust-lang.org> | 2024-03-05 05:33:17 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-03-05 05:33:17 +0000 |
| commit | 5a1e5449c8f4cb6b12b4f64238e3c058767ebf02 (patch) | |
| tree | 4102b1513c18da765a4263bbb0efa8649b169823 /compiler/rustc_llvm/llvm-wrapper/SymbolWrapper.cpp | |
| parent | 1547c076bfec8abb819d6a81e1e4095d267bd5b4 (diff) | |
| parent | c85a9df31a0d530b1847f5f46d1388fa39332b41 (diff) | |
| download | rust-5a1e5449c8f4cb6b12b4f64238e3c058767ebf02.tar.gz rust-5a1e5449c8f4cb6b12b4f64238e3c058767ebf02.zip | |
Auto merge of #121001 - nyurik:optimize-core-fmt, r=cuviper
perf: improve write_fmt to handle simple strings
In case format string has no arguments, simplify its implementation with a direct call to `output.write_str(value)`. This builds on `@dtolnay` original [suggestion](https://github.com/serde-rs/serde/pull/2697#issuecomment-1940376414). This does not change any expectations because the original `fn write()` implementation calls `write_str` for parts of the format string.
```rust
write!(f, "text") -> f.write_str("text")
```
```diff
/// [`write!`]: crate::write!
+#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn write(output: &mut dyn Write, args: Arguments<'_>) -> Result {
+ if let Some(s) = args.as_str() { output.write_str(s) } else { write_internal(output, args) }
+}
+
+/// Actual implementation of the [`write`], but without the simple string optimization.
+fn write_internal(output: &mut dyn Write, args: Arguments<'_>) -> Result {
let mut formatter = Formatter::new(output);
let mut idx = 0;
```
* Hopefully it will improve the simple case for the https://github.com/rust-lang/rust/issues/99012
* Another related (original?) issues #10761
* Previous similar attempt to fix it by by `@Kobzol` #100700
CC: `@m-ou-se` as probably the biggest expert in everything `format!`
Diffstat (limited to 'compiler/rustc_llvm/llvm-wrapper/SymbolWrapper.cpp')
0 files changed, 0 insertions, 0 deletions
