From 06f2d818fe7bca4c5d0915b17f6b26a463953068 Mon Sep 17 00:00:00 2001 From: overlookmotel <557937+overlookmotel@users.noreply.github.com> Date: Mon, 19 Aug 2024 01:32:05 +0000 Subject: [PATCH] refactor(linter): avoid unnecessary temp `Vec`s (#4963) Use iterator instead of collecting into temporary `Vec` which is then iterated over. --- crates/oxc_linter/src/utils/jest.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/oxc_linter/src/utils/jest.rs b/crates/oxc_linter/src/utils/jest.rs index e5e400bbbe693..8a3cc91b8e41b 100644 --- a/crates/oxc_linter/src/utils/jest.rs +++ b/crates/oxc_linter/src/utils/jest.rs @@ -160,9 +160,8 @@ pub fn collect_possible_jest_call_node<'a, 'b>( { reference_id_with_original_list.extend( collect_ids_referenced_to_global(ctx) - .iter() // set the original of global test function to None - .map(|&id| (id, None)), + .map(|id| (id, None)), ); } @@ -239,13 +238,14 @@ fn find_original_name<'a>(import_decl: &'a ImportDeclaration<'a>, name: &str) -> }) } -fn collect_ids_referenced_to_global(ctx: &LintContext) -> Vec { +fn collect_ids_referenced_to_global<'c>( + ctx: &'c LintContext, +) -> impl Iterator + 'c { ctx.scopes() .root_unresolved_references() .iter() .filter(|(name, _)| JEST_METHOD_NAMES.contains(name.as_str())) - .flat_map(|(_, reference_ids)| reference_ids.clone()) - .collect() + .flat_map(|(_, reference_ids)| reference_ids.iter().copied()) } /// join name of the expression. e.g.