mirror of
https://github.com/oxc-project/oxc.git
synced 2026-11-04 10:29:58 +00:00
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:
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)) {
|
||||
|
||||
Reference in new issue
Block a user