perf(linter): reduce no-duplicate-case allocations (#28477)

Use smallvec for storing previous case expressions to avoid frequent
heap allocs.

On local fixtures:



Metric | Before → After
-- | --
Allocations | 284 → 63 (−77.8%)
Reallocations | 242 → 36 (−85.1%)
Allocated bytes | 24,096 → 14,464 (−40.0%)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
Cam McHenryandCopilot authored and GitHub committed 2026-10-30 12:26:33 -04:00
1 parent 6a72d840ed
commit f01d52da4c
1 file changed
+2 -1
@@ -2,6 +2,7 @@ use oxc_ast::ast::Expression;
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::{ContentEq, GetSpan, Span};
use smallvec::SmallVec;
use crate::{AstNode, context::LintContext, rule::Rule};
@@ -85,7 +86,7 @@ declare_oxc_lint!(
impl Rule for NoDuplicateCase {
fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) {
let Some(ss) = node.kind().as_switch_statement() else { return };
let mut previous_tests: Vec<&Expression<'_>> = vec![];
let mut previous_tests: SmallVec<[&Expression<'_>; 8]> = SmallVec::new();
for test in ss.cases.iter().filter_map(|c| c.test.as_ref()) {
let test = test.without_parentheses();
if let Some(prev) = previous_tests.iter().find(|t| t.content_eq(test)) {