about summary refs log tree commit diff
path: root/src/libsyntax/parse/parser.rs
diff options
context:
space:
mode:
authorNicholas Nethercote <nnethercote@mozilla.com>2018-11-29 11:36:58 +1100
committerNicholas Nethercote <nnethercote@mozilla.com>2018-11-29 17:12:18 +1100
commit787959c20d062d396b97a5566e0a766d963af022 (patch)
tree4c4ca4239498d04470b497e5c6e7d0bb16cd1ffc /src/libsyntax/parse/parser.rs
parentdeb9195e5749c4f15e9a5ae0e7ee8e1802c716e4 (diff)
downloadrust-787959c20d062d396b97a5566e0a766d963af022.tar.gz
rust-787959c20d062d396b97a5566e0a766d963af022.zip
Use `Cow` in `Token::String`.
`Printer::word` takes a `&str` and converts it into a `String`, which
causes an allocation. But that allocation is rarely necessary, because
`&str` is almost always a `&'static str` or a `String` that won't be
used again.

This commit changes `Token::String` so it holds a `Cow<'static, str>`
instead of a `String`, which avoids a lot of allocations.
Diffstat (limited to 'src/libsyntax/parse/parser.rs')
-rw-r--r--src/libsyntax/parse/parser.rs2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index e2f09affd4f..99a59fa8a75 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -2795,7 +2795,7 @@ impl<'a> Parser<'a> {
                             s.print_usize(float.trunc() as usize)?;
                             s.pclose()?;
                             s.s.word(".")?;
-                            s.s.word(fstr.splitn(2, ".").last().unwrap())
+                            s.s.word(fstr.splitn(2, ".").last().unwrap().to_string())
                         });
                         err.span_suggestion_with_applicability(
                             lo.to(self.prev_span),