Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fmt: Skip calling write_str for empty strings
`format_args!` uses one string literal per used `{}`, in many cases, the separating string pieces are empty. For example, `write!(w, "{}", x);` will attempt to write one empty string before the `{}` format, and `write!(w, "{}{}{}", x, y, z);" will write three empty string pieces between formats. Simply skip writing if the string is empty. It is a cheap branch compared to the virtual Write::write_str call that it makes possible to skip. It does not solve issue rust-lang#10761 in any way, yet that's where I noticed this. The testcase in the issue shows a performance difference between `write!(w, "abc")` and `write!(w, "{}", "abc")`, and this change halves the size of the difference.
- Loading branch information