about summary refs log tree commit diff
path: root/src/libsyntax_ext
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2018-07-29 09:33:37 +0000
committerbors <bors@rust-lang.org>2018-07-29 09:33:37 +0000
commit023fd7e74a9eb5bafcb75fcbe69b7110e9de4492 (patch)
treec9b50228b27509d45f6d73e33aaec6b482c80c36 /src/libsyntax_ext
parenta5c2d0fffaaf0b764c01bc4066e51ffd475ceae9 (diff)
parent57a5a9b05423c4f832cd9a3aaa7e06d55fab6efa (diff)
downloadrust-023fd7e74a9eb5bafcb75fcbe69b7110e9de4492.tar.gz
rust-023fd7e74a9eb5bafcb75fcbe69b7110e9de4492.zip
Auto merge of #52767 - ljedrz:avoid_format, r=petrochenkov
Prefer to_string() to format!()

Simple benchmarks suggest in some cases it can be faster by even 37%:
```
test converting_f64_long  ... bench:         339 ns/iter (+/- 199)
test converting_f64_short ... bench:         136 ns/iter (+/- 34)
test converting_i32_long  ... bench:          87 ns/iter (+/- 16)
test converting_i32_short ... bench:          87 ns/iter (+/- 49)
test converting_str       ... bench:          54 ns/iter (+/- 15)
test formatting_f64_long  ... bench:         349 ns/iter (+/- 176)
test formatting_f64_short ... bench:         145 ns/iter (+/- 14)
test formatting_i32_long  ... bench:          98 ns/iter (+/- 14)
test formatting_i32_short ... bench:          93 ns/iter (+/- 15)
test formatting_str       ... bench:          86 ns/iter (+/- 23)
```
Diffstat (limited to 'src/libsyntax_ext')
-rw-r--r--src/libsyntax_ext/concat.rs4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/libsyntax_ext/concat.rs b/src/libsyntax_ext/concat.rs
index 99dba8af754..dcdd2c590e0 100644
--- a/src/libsyntax_ext/concat.rs
+++ b/src/libsyntax_ext/concat.rs
@@ -42,10 +42,10 @@ pub fn expand_syntax_ext(
                 ast::LitKind::Int(i, ast::LitIntType::Unsigned(_))
                 | ast::LitKind::Int(i, ast::LitIntType::Signed(_))
                 | ast::LitKind::Int(i, ast::LitIntType::Unsuffixed) => {
-                    accumulator.push_str(&format!("{}", i));
+                    accumulator.push_str(&i.to_string());
                 }
                 ast::LitKind::Bool(b) => {
-                    accumulator.push_str(&format!("{}", b));
+                    accumulator.push_str(&b.to_string());
                 }
                 ast::LitKind::Byte(..) | ast::LitKind::ByteStr(..) => {
                     cx.span_err(e.span, "cannot concatenate a byte string literal");