Remove some unneeded string allocations

This commit is contained in:
Lukas Wirth 2020-12-31 10:13:14 +01:00
parent a9814fa9c0
commit 816190c6f6
3 changed files with 5 additions and 3 deletions

View File

@ -234,7 +234,7 @@ fn parse_comma_sep_input(derive_input: ast::TokenTree) -> Result<FxHashSet<Strin
current_derive = String::new(); current_derive = String::new();
} }
} else { } else {
current_derive.push_str(token.to_string().trim()); current_derive.push_str(token.text().trim());
} }
} }

View File

@ -454,7 +454,7 @@ mod diagnostics {
}); });
for token in tokens { for token in tokens {
if token.kind() == SyntaxKind::IDENT if token.kind() == SyntaxKind::IDENT
&& token.to_string() == *name && token.text() == name.as_str()
{ {
precise_location = Some(token.text_range()); precise_location = Some(token.text_range());
break 'outer; break 'outer;

View File

@ -473,7 +473,9 @@ impl<'db, 'sema> Matcher<'db, 'sema> {
} }
SyntaxElement::Node(n) => { SyntaxElement::Node(n) => {
if let Some(first_token) = n.first_token() { if let Some(first_token) = n.first_token() {
if Some(first_token.to_string()) == next_pattern_token { if Some(first_token.text().as_str())
== next_pattern_token.as_deref()
{
if let Some(SyntaxElement::Node(p)) = pattern.next() { if let Some(SyntaxElement::Node(p)) = pattern.next() {
// We have a subtree that starts with the next token in our pattern. // We have a subtree that starts with the next token in our pattern.
self.attempt_match_token_tree(phase, &p, &n)?; self.attempt_match_token_tree(phase, &p, &n)?;