chore(cli,ext,rt): remove some unnecessary clone or malloc (#17261)

This commit is contained in:
Yiyu Lin 2023-01-04 20:20:36 +08:00 committed by GitHub
parent 2da882137e
commit 319f607476
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 23 additions and 18 deletions

View file

@ -340,9 +340,9 @@ impl Diagnostics {
/// returns `true` are included.
pub fn filter<P>(&self, predicate: P) -> Self
where
P: FnMut(&Diagnostic) -> bool,
P: FnMut(&Diagnostic) -> Option<Diagnostic>,
{
let diagnostics = self.0.clone().into_iter().filter(predicate).collect();
let diagnostics = self.0.iter().filter_map(predicate).collect();
Self(diagnostics)
}