Skip to content

Commit da87390

Browse files
committed
perf(linter): replace phf_set with array in jsx-a11y/autocomplete-valid (#10484)
Related to #10076
1 parent d4033bc commit da87390

File tree

1 file changed

+47
-66
lines changed

1 file changed

+47
-66
lines changed

crates/oxc_linter/src/rules/jsx_a11y/autocomplete_valid.rs

Lines changed: 47 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use oxc_ast::{
55
use oxc_diagnostics::OxcDiagnostic;
66
use oxc_macros::declare_oxc_lint;
77
use oxc_span::{CompactStr, Span};
8-
use phf::{phf_map, phf_set};
98
use rustc_hash::FxHashSet;
109
use serde_json::Value;
1110

@@ -66,98 +65,80 @@ impl std::default::Default for AutocompleteValidConfig {
6665
}
6766
}
6867

69-
static VALID_AUTOCOMPLETE_VALUES: phf::Set<&'static str> = phf_set! {
70-
"on",
71-
"name",
72-
"email",
73-
"username",
74-
"new-password",
75-
"current-password",
76-
"one-time-code",
77-
"off",
78-
"organization-title",
79-
"organization",
80-
"street-address",
68+
static VALID_AUTOCOMPLETE_VALUES: [&str; 49] = [
69+
"address-level1",
70+
"address-level2",
71+
"address-level3",
72+
"address-level4",
8173
"address-line1",
8274
"address-line2",
8375
"address-line3",
84-
"address-level4",
85-
"address-level3",
86-
"address-level2",
87-
"address-level1",
88-
"country",
89-
"country-name",
90-
"postal-code",
91-
"cc-name",
92-
"cc-given-name",
76+
"bday",
77+
"bday-day",
78+
"bday-month",
79+
"bday-year",
9380
"cc-additional-name",
94-
"cc-family-name",
95-
"cc-number",
81+
"cc-csc",
9682
"cc-exp",
9783
"cc-exp-month",
9884
"cc-exp-year",
99-
"cc-csc",
85+
"cc-family-name",
86+
"cc-given-name",
87+
"cc-name",
88+
"cc-number",
10089
"cc-type",
101-
"transaction-currency",
102-
"transaction-amount",
90+
"country",
91+
"country-name",
92+
"current-password",
93+
"email",
94+
"impp",
10395
"language",
104-
"bday",
105-
"bday-day",
106-
"bday-month",
107-
"bday-year",
96+
"name",
97+
"new-password",
98+
"off",
99+
"on",
100+
"one-time-code",
101+
"organization",
102+
"organization-title",
103+
"photo",
104+
"postal-code",
108105
"sex",
106+
"street-address",
109107
"tel",
110-
"tel-country-code",
111-
"tel-national",
112108
"tel-area-code",
113-
"tel-local",
109+
"tel-country-code",
114110
"tel-extension",
115-
"impp",
111+
"tel-local",
112+
"tel-national",
113+
"transaction-amount",
114+
"transaction-currency",
116115
"url",
117-
"photo",
116+
"username",
118117
"webauthn",
119-
};
118+
];
120119

121-
static BILLING: phf::Set<&'static str> = phf_set! {
122-
"street-address",
123-
"address-line1",
124-
"address-line2",
125-
"address-line3",
126-
"address-level4",
127-
"address-level3",
128-
"address-level2",
120+
static BILLING_AND_SHIPPING: [&str; 11] = [
129121
"address-level1",
130-
"country",
131-
"country-name",
132-
"postal-code",
133-
};
134-
135-
static SHIPPING: phf::Set<&'static str> = phf_set! {
136-
"street-address",
122+
"address-level2",
123+
"address-level3",
124+
"address-level4",
137125
"address-line1",
138126
"address-line2",
139127
"address-line3",
140-
"address-level4",
141-
"address-level3",
142-
"address-level2",
143-
"address-level1",
144128
"country",
145129
"country-name",
146130
"postal-code",
147-
};
148-
149-
static VALID_AUTOCOMPLETE_COMBINATIONS: phf::Map<&'static str, &'static phf::Set<&'static str>> = phf_map! {
150-
"billing" => &BILLING,
151-
"shipping" => &SHIPPING,
152-
};
131+
"street-address",
132+
];
153133

154134
fn is_valid_autocomplete_value(value: &str) -> bool {
155135
let parts: Vec<&str> = value.split_whitespace().collect();
136+
156137
match parts.len() {
157-
1 => VALID_AUTOCOMPLETE_VALUES.contains(parts[0]),
158-
2 => VALID_AUTOCOMPLETE_COMBINATIONS
159-
.get(parts[0])
160-
.is_some_and(|valid_suffixes| valid_suffixes.contains(parts[1])),
138+
1 => VALID_AUTOCOMPLETE_VALUES.binary_search(&parts[0]).is_ok(),
139+
2 if ["billing", "shipping"].contains(&parts[0]) => {
140+
BILLING_AND_SHIPPING.binary_search(&parts[1]).is_ok()
141+
}
161142
_ => false,
162143
}
163144
}

0 commit comments

Comments
 (0)