From a6cbaeae8dc11e1de7a4424cba48de5939999c90 Mon Sep 17 00:00:00 2001 From: overlookmotel Date: Thu, 25 Jul 2024 21:46:04 +0100 Subject: [PATCH] perf(linter): `no_shadow_restricted_names` only look up name in hashmap once --- .../rules/eslint/no_shadow_restricted_names.rs | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/crates/oxc_linter/src/rules/eslint/no_shadow_restricted_names.rs b/crates/oxc_linter/src/rules/eslint/no_shadow_restricted_names.rs index e00c19700f847..7dde15aab34c7 100644 --- a/crates/oxc_linter/src/rules/eslint/no_shadow_restricted_names.rs +++ b/crates/oxc_linter/src/rules/eslint/no_shadow_restricted_names.rs @@ -36,13 +36,6 @@ declare_oxc_lint!( correctness ); -#[inline] -fn check_and_diagnostic(s: &str, span: Span, ctx: &LintContext) { - if PRE_DEFINE_VAR.contains_key(s) { - ctx.diagnostic(no_shadow_restricted_names_diagnostic(s, span)); - } -} - impl Rule for NoShadowRestrictedNames { fn run_once(&self, ctx: &LintContext<'_>) { ctx.symbols().iter().for_each(|symbol_id| { @@ -63,9 +56,13 @@ impl Rule for NoShadowRestrictedNames { } } - check_and_diagnostic(name, ctx.symbols().get_span(symbol_id), ctx); - for span in ctx.symbols().get_redeclarations(symbol_id) { - check_and_diagnostic(name, *span, ctx); + if PRE_DEFINE_VAR.contains_key(name) { + let span = ctx.symbols().get_span(symbol_id); + ctx.diagnostic(no_shadow_restricted_names_diagnostic(name, span)); + + for &span in ctx.symbols().get_redeclarations(symbol_id) { + ctx.diagnostic(no_shadow_restricted_names_diagnostic(name, span)); + } } }); }