Skip to content

Commit 17c7bda

Browse files
committed
perf(linter): replace phf_set with array in unicorn/prefer-type-error (oxc-project#10426)
Related to oxc-project#10076
1 parent 5cde29b commit 17c7bda

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,11 @@ fn is_typechecking_call_expr(call_expr: &CallExpression) -> bool {
129129

130130
match &call_expr.callee {
131131
Expression::Identifier(ident) => {
132-
TYPE_CHECKING_GLOBAL_IDENTIFIERS.contains(ident.name.as_str())
132+
TYPE_CHECKING_GLOBAL_IDENTIFIERS.contains(&ident.name.as_str())
133133
}
134134
callee @ match_member_expression!(Expression) => {
135135
if let Some(ident) = callee.to_member_expression().static_property_name() {
136-
return TYPE_CHECKING_IDENTIFIERS.contains(ident);
136+
return TYPE_CHECKING_IDENTIFIERS.binary_search(&ident).is_ok();
137137
}
138138
false
139139
}
@@ -143,13 +143,13 @@ fn is_typechecking_call_expr(call_expr: &CallExpression) -> bool {
143143

144144
fn is_type_checking_member_expr(member_expr: &MemberExpression) -> bool {
145145
if let Some(ident) = member_expr.static_property_name() {
146-
return TYPE_CHECKING_IDENTIFIERS.contains(ident);
146+
return TYPE_CHECKING_IDENTIFIERS.binary_search(&ident).is_ok();
147147
}
148148

149149
false
150150
}
151151

152-
const TYPE_CHECKING_IDENTIFIERS: phf::Set<&'static str> = phf::phf_set!(
152+
const TYPE_CHECKING_IDENTIFIERS: [&str; 36] = [
153153
"isArray",
154154
"isArrayBuffer",
155155
"isArrayLike",
@@ -186,10 +186,9 @@ const TYPE_CHECKING_IDENTIFIERS: phf::Set<&'static str> = phf::phf_set!(
186186
"isWeakSet",
187187
"isWindow",
188188
"isXMLDoc",
189-
);
189+
];
190190

191-
const TYPE_CHECKING_GLOBAL_IDENTIFIERS: phf::Set<&'static str> =
192-
phf::phf_set!("isFinite", "isNaN",);
191+
const TYPE_CHECKING_GLOBAL_IDENTIFIERS: [&str; 2] = ["isFinite", "isNaN"];
193192

194193
#[test]
195194
fn test() {

0 commit comments

Comments
 (0)