Skip to content

Commit

Permalink
refactor(linter): avoid unnecessary temp Vecs (#4963)
Browse files Browse the repository at this point in the history
Use iterator instead of collecting into temporary `Vec` which is then iterated over.
  • Loading branch information
overlookmotel committed Aug 19, 2024
1 parent d677b8e commit 06f2d81
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions crates/oxc_linter/src/utils/jest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
);
}

Expand Down Expand Up @@ -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<ReferenceId> {
fn collect_ids_referenced_to_global<'c>(
ctx: &'c LintContext,
) -> impl Iterator<Item = ReferenceId> + '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.
Expand Down

0 comments on commit 06f2d81

Please sign in to comment.