Skip to content

Commit 7ef1e0d

Browse files
committed
perf(linter): replace phf_set with array in unicorn/new-for-builtins (oxc-project#10424)
Related to oxc-project#10076
1 parent 4817c7e commit 7ef1e0d

File tree

1 file changed

+20
-21
lines changed

1 file changed

+20
-21
lines changed

crates/oxc_linter/src/rules/unicorn/new_for_builtins.rs

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use oxc_diagnostics::OxcDiagnostic;
33
use oxc_macros::declare_oxc_lint;
44
use oxc_span::Span;
55
use oxc_syntax::operator::BinaryOperator;
6-
use phf::phf_set;
76

87
use crate::{AstNode, context::LintContext, globals::GLOBAL_OBJECT_NAMES, rule::Rule};
98

@@ -69,7 +68,7 @@ impl Rule for NewForBuiltins {
6968
return;
7069
};
7170

72-
if ENFORCE_NEW_FOR_BUILTINS.contains(builtin_name) {
71+
if ENFORCE_NEW_FOR_BUILTINS.binary_search(&builtin_name).is_ok() {
7372
if builtin_name == "Object" {
7473
let parent_kind = ctx.nodes().parent_kind(node.id());
7574
if let Some(AstKind::BinaryExpression(bin_expr)) = parent_kind {
@@ -116,36 +115,36 @@ fn is_expr_global_builtin<'a, 'b>(
116115
}
117116
}
118117

119-
const ENFORCE_NEW_FOR_BUILTINS: phf::Set<&'static str> = phf_set! {
120-
"Int8Array",
121-
"Uint8Array",
122-
"Uint8ClampedArray",
123-
"Int16Array",
124-
"Uint16Array",
125-
"Int32Array",
126-
"Uint32Array",
127-
"Float32Array",
128-
"Float64Array",
129-
"BigInt64Array",
130-
"BigUint64Array",
131-
"Object",
118+
const ENFORCE_NEW_FOR_BUILTINS: [&str; 28] = [
132119
"Array",
133120
"ArrayBuffer",
121+
"BigInt64Array",
122+
"BigUint64Array",
134123
"DataView",
135124
"Date",
136125
"Error",
126+
"FinalizationRegistry",
127+
"Float32Array",
128+
"Float64Array",
137129
"Function",
130+
"Int16Array",
131+
"Int32Array",
132+
"Int8Array",
138133
"Map",
139-
"WeakMap",
140-
"Set",
141-
"WeakSet",
134+
"Object",
142135
"Promise",
136+
"Proxy",
143137
"RegExp",
138+
"Set",
144139
"SharedArrayBuffer",
145-
"Proxy",
140+
"Uint16Array",
141+
"Uint32Array",
142+
"Uint8Array",
143+
"Uint8ClampedArray",
144+
"WeakMap",
146145
"WeakRef",
147-
"FinalizationRegistry",
148-
};
146+
"WeakSet",
147+
];
149148

150149
const DISALLOW_NEW_FOR_BUILTINS: [&str; 5] = ["BigInt", "Boolean", "Number", "Symbol", "String"];
151150

0 commit comments

Comments
 (0)