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.
This commit is contained in:
parent
deb9195e57
commit
787959c20d
7 changed files with 101 additions and 88 deletions
|
@ -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),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue