some clippy::performance fixes

use vec![] instead of Vec::new() +  push()
avoid redundant clones
use chars instead of &str for single char patterns in ends_with() and starts_with()
allocate some Vecs with capacity to avoid unneccessary resizing
This commit is contained in:
Matthias Krüger
2021-03-15 10:15:08 +01:00
parent de36027541
commit cad617bba0
9 changed files with 13 additions and 19 deletions

View File

@@ -222,14 +222,10 @@ fn convert_doc_comment(token: &syntax::SyntaxToken) -> Option<Vec<tt::TokenTree>
let doc = comment.kind().doc?;
// Make `doc="\" Comments\""
let mut meta_tkns = Vec::new();
meta_tkns.push(mk_ident("doc"));
meta_tkns.push(mk_punct('='));
meta_tkns.push(mk_doc_literal(&comment));
let meta_tkns = vec![mk_ident("doc"), mk_punct('='), mk_doc_literal(&comment)];
// Make `#![]`
let mut token_trees = Vec::new();
token_trees.push(mk_punct('#'));
let mut token_trees = vec![mk_punct('#')];
if let ast::CommentPlacement::Inner = doc {
token_trees.push(mk_punct('!'));
}