Skip to content

Commit 04e2de5

Browse files
committed
perf(linter): avoid iteration when checking import is AllButDefault or SideEffect in eslint/no-duplicate-imports (#12093)
Avoid the 3 iterations ``` let namespace = existing.iter().find(|(t, _, _)| matches!(t, ImportType::Namespace)); let named = existing.iter().find(|(t, _, _)| matches!(t, ImportType::Named)); let default = existing.iter().find(|(t, _, _)| matches!(t, ImportType::Default)); ``` when the `ImportType` is `SideEffect` or `AllButDefault`. Their results are not needed for the two types.
1 parent 9240342 commit 04e2de5

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

crates/oxc_linter/src/rules/eslint/no_duplicate_imports.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,14 @@ fn can_merge_imports(
303303
current_type: &ImportType,
304304
existing: &[(ImportType, Span, ModuleType)],
305305
) -> bool {
306+
if *current_type == ImportType::AllButDefault {
307+
return false;
308+
}
309+
310+
if *current_type == ImportType::SideEffect {
311+
return !existing.is_empty();
312+
}
313+
306314
let namespace = existing.iter().find(|(t, _, _)| matches!(t, ImportType::Namespace));
307315
let named = existing.iter().find(|(t, _, _)| matches!(t, ImportType::Named));
308316
let default = existing.iter().find(|(t, _, _)| matches!(t, ImportType::Default));
@@ -333,8 +341,7 @@ fn can_merge_imports(
333341
has_namespace || has_default
334342
}
335343
ImportType::Default => has_default || has_namespace || has_named,
336-
ImportType::SideEffect => !existing.is_empty(),
337-
ImportType::AllButDefault => false,
344+
_ => unreachable!("other ImportType values should be already checked"),
338345
}
339346
}
340347

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy