Skip to content

Commit d4033bc

Browse files
committed
perf(linter): replace phf_set with array in globals.rs (#10483)
Related to #10076
1 parent 852c8a7 commit d4033bc

File tree

9 files changed

+138
-140
lines changed

9 files changed

+138
-140
lines changed

crates/oxc_linter/src/globals.rs

Lines changed: 129 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use phf::phf_set;
2-
31
pub const GLOBAL_OBJECT_NAMES: [&str; 4] = ["global", "globalThis", "self", "window"];
42

53
/// set of reserved HTML tag names definition
@@ -192,135 +190,135 @@ pub fn is_valid_aria_property(name: &str) -> bool {
192190
/// set of valid ARIA role definitions
193191
/// Reference: <https://www.w3.org/TR/wai-aria/#role_definitions>
194192
/// Reference: <https://github.com/A11yance/aria-query/blob/v5.3.2/src/rolesMap.js>
195-
pub const VALID_ARIA_ROLES: phf::Set<&'static str> = phf_set! {
196-
"alert",
197-
"alertdialog",
198-
"application",
199-
"article",
200-
"banner",
201-
"blockquote",
202-
"button",
203-
"caption",
204-
"cell",
205-
"checkbox",
206-
"code",
207-
"columnheader",
208-
"combobox",
209-
"complementary",
210-
"contentinfo",
211-
"definition",
212-
"deletion",
213-
"dialog",
214-
"directory",
215-
"doc-abstract",
216-
"doc-acknowledgments",
217-
"doc-afterword",
218-
"doc-appendix",
219-
"doc-backlink",
220-
"doc-biblioentry",
221-
"doc-bibliography",
222-
"doc-biblioref",
223-
"doc-chapter",
224-
"doc-colophon",
225-
"doc-conclusion",
226-
"doc-cover",
227-
"doc-credit",
228-
"doc-credits",
229-
"doc-dedication",
230-
"doc-endnote",
231-
"doc-endnotes",
232-
"doc-epigraph",
233-
"doc-epilogue",
234-
"doc-errata",
235-
"doc-example",
236-
"doc-footnote",
237-
"doc-foreword",
238-
"doc-glossary",
239-
"doc-glossref",
240-
"doc-index",
241-
"doc-introduction",
242-
"doc-noteref",
243-
"doc-notice",
244-
"doc-pagebreak",
245-
"doc-pagelist",
246-
"doc-part",
247-
"doc-preface",
248-
"doc-prologue",
249-
"doc-pullquote",
250-
"doc-qna",
251-
"doc-subtitle",
252-
"doc-tip",
253-
"doc-toc",
254-
"document",
255-
"emphasis",
256-
"feed",
257-
"figure",
258-
"form",
259-
"generic",
260-
"graphics-document",
261-
"graphics-object",
262-
"graphics-symbol",
263-
"grid",
264-
"gridcell",
265-
"group",
266-
"heading",
267-
"img",
268-
"insertion",
269-
"link",
270-
"list",
271-
"listbox",
272-
"listitem",
273-
"log",
274-
"main",
275-
"mark",
276-
"marquee",
277-
"math",
278-
"menu",
279-
"menubar",
280-
"menuitem",
281-
"menuitemcheckbox",
282-
"menuitemradio",
283-
"meter",
284-
"navigation",
285-
"none",
286-
"note",
287-
"option",
288-
"paragraph",
289-
"presentation",
290-
"progressbar",
291-
"radio",
292-
"radiogroup",
293-
"region",
294-
"row",
295-
"rowgroup",
296-
"rowheader",
297-
"scrollbar",
298-
"search",
299-
"searchbox",
300-
"separator",
301-
"slider",
302-
"spinbutton",
303-
"status",
304-
"strong",
305-
"subscript",
306-
"superscript",
307-
"switch",
308-
"tab",
309-
"table",
310-
"tablist",
311-
"tabpanel",
312-
"term",
313-
"textbox",
314-
"time",
315-
"timer",
316-
"toolbar",
317-
"tooltip",
318-
"tree",
319-
"treegrid",
320-
"treeitem"
321-
};
193+
pub const VALID_ARIA_ROLES: [&str; 125] = [
194+
"alert",
195+
"alertdialog",
196+
"application",
197+
"article",
198+
"banner",
199+
"blockquote",
200+
"button",
201+
"caption",
202+
"cell",
203+
"checkbox",
204+
"code",
205+
"columnheader",
206+
"combobox",
207+
"complementary",
208+
"contentinfo",
209+
"definition",
210+
"deletion",
211+
"dialog",
212+
"directory",
213+
"doc-abstract",
214+
"doc-acknowledgments",
215+
"doc-afterword",
216+
"doc-appendix",
217+
"doc-backlink",
218+
"doc-biblioentry",
219+
"doc-bibliography",
220+
"doc-biblioref",
221+
"doc-chapter",
222+
"doc-colophon",
223+
"doc-conclusion",
224+
"doc-cover",
225+
"doc-credit",
226+
"doc-credits",
227+
"doc-dedication",
228+
"doc-endnote",
229+
"doc-endnotes",
230+
"doc-epigraph",
231+
"doc-epilogue",
232+
"doc-errata",
233+
"doc-example",
234+
"doc-footnote",
235+
"doc-foreword",
236+
"doc-glossary",
237+
"doc-glossref",
238+
"doc-index",
239+
"doc-introduction",
240+
"doc-noteref",
241+
"doc-notice",
242+
"doc-pagebreak",
243+
"doc-pagelist",
244+
"doc-part",
245+
"doc-preface",
246+
"doc-prologue",
247+
"doc-pullquote",
248+
"doc-qna",
249+
"doc-subtitle",
250+
"doc-tip",
251+
"doc-toc",
252+
"document",
253+
"emphasis",
254+
"feed",
255+
"figure",
256+
"form",
257+
"generic",
258+
"graphics-document",
259+
"graphics-object",
260+
"graphics-symbol",
261+
"grid",
262+
"gridcell",
263+
"group",
264+
"heading",
265+
"img",
266+
"insertion",
267+
"link",
268+
"list",
269+
"listbox",
270+
"listitem",
271+
"log",
272+
"main",
273+
"mark",
274+
"marquee",
275+
"math",
276+
"menu",
277+
"menubar",
278+
"menuitem",
279+
"menuitemcheckbox",
280+
"menuitemradio",
281+
"meter",
282+
"navigation",
283+
"none",
284+
"note",
285+
"option",
286+
"paragraph",
287+
"presentation",
288+
"progressbar",
289+
"radio",
290+
"radiogroup",
291+
"region",
292+
"row",
293+
"rowgroup",
294+
"rowheader",
295+
"scrollbar",
296+
"search",
297+
"searchbox",
298+
"separator",
299+
"slider",
300+
"spinbutton",
301+
"status",
302+
"strong",
303+
"subscript",
304+
"superscript",
305+
"switch",
306+
"tab",
307+
"table",
308+
"tablist",
309+
"tabpanel",
310+
"term",
311+
"textbox",
312+
"time",
313+
"timer",
314+
"toolbar",
315+
"tooltip",
316+
"tree",
317+
"treegrid",
318+
"treeitem",
319+
];
322320

323-
pub const HTML_TAG: phf::Set<&'static str> = phf_set! {
321+
pub const HTML_TAG: [&str; 149] = [
324322
"a",
325323
"abbr",
326324
"acronym",
@@ -470,4 +468,4 @@ pub const HTML_TAG: phf::Set<&'static str> = phf_set! {
470468
"video",
471469
"wbr",
472470
"xmp",
473-
};
471+
];

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ impl Rule for AriaActivedescendantHasTabindex {
6767

6868
let element_type = get_element_type(ctx, jsx_opening_el);
6969

70-
if !HTML_TAG.contains(&element_type) {
70+
if HTML_TAG.binary_search(&element_type.as_ref()).is_err() {
7171
return;
7272
}
7373

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ impl Rule for AriaRole {
146146
if let Some(aria_role) = has_jsx_prop(&jsx_el.opening_element, "role") {
147147
let element_type = get_element_type(ctx, &jsx_el.opening_element);
148148

149-
if self.ignore_non_dom && !HTML_TAG.contains(&element_type) {
149+
if self.ignore_non_dom && HTML_TAG.binary_search(&element_type.as_ref()).is_err() {
150150
return;
151151
}
152152

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl Rule for ClickEventsHaveKeyEvents {
6262
// Check only native DOM elements or custom component via settings
6363
let element_type = get_element_type(ctx, jsx_opening_el);
6464

65-
if !HTML_TAG.contains(&element_type) {
65+
if HTML_TAG.binary_search(&element_type.as_ref()).is_err() {
6666
return;
6767
}
6868

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ impl Rule for MouseEventsHaveKeyEvents {
105105

106106
let el_type = get_element_type(ctx, jsx_opening_el);
107107

108-
if !HTML_TAG.contains(&el_type) {
108+
if HTML_TAG.binary_search(&el_type.as_ref()).is_err() {
109109
return;
110110
}
111111

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ impl Rule for NoAutofocus {
105105
let element_type = get_element_type(ctx, &jsx_el.opening_element);
106106

107107
if self.ignore_non_dom {
108-
if HTML_TAG.contains(&element_type) {
108+
if HTML_TAG.binary_search(&element_type.as_ref()).is_ok() {
109109
if let JSXAttributeItem::Attribute(attr) = autofocus {
110110
ctx.diagnostic_with_fix(no_autofocus_diagnostic(attr.span), |fixer| {
111111
fixer.delete(&attr.span)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ impl Rule for RoleSupportsAriaProps {
7878
);
7979
let is_implicit = role_value.is_some() && role.is_none();
8080
if let Some(role_value) = role_value {
81-
if !VALID_ARIA_ROLES.contains(role_value) {
81+
if VALID_ARIA_ROLES.binary_search(&role_value).is_err() {
8282
return;
8383
}
8484
for attr in &jsx_el.attributes {
@@ -157,7 +157,7 @@ fn get_implicit_role<'a>(
157157
_ => "",
158158
};
159159

160-
if VALID_ARIA_ROLES.contains(implicit_role) { Some(implicit_role) } else { None }
160+
VALID_ARIA_ROLES.binary_search(&implicit_role).is_ok().then_some(implicit_role)
161161
}
162162

163163
const ALERT_ETC_PROPS: &[AriaProperty] = &[

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ impl Rule for Scope {
7272
return;
7373
}
7474

75-
if !HTML_TAG.contains(&element_type) {
75+
if HTML_TAG.binary_search(&element_type.as_ref()).is_err() {
7676
return;
7777
}
7878

crates/oxc_linter/src/rules/react/self_closing_comp.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ impl Rule for SelfClosingComp {
116116
let mut is_dom_comp = false;
117117
if !is_comp {
118118
if let Some(tag_name) = jsx_el.opening_element.name.get_identifier_name() {
119-
is_dom_comp = HTML_TAG.contains(&tag_name);
119+
is_dom_comp = HTML_TAG.binary_search(&tag_name.as_str()).is_ok();
120120
}
121121
}
122122

0 commit comments

Comments
 (0)