Skip to content

Commit 2b17003

Browse files
committedSep 23, 2024·
perf(linter, prettier, diagnostics): use FxHashMap instead of std::collections::HashMap (#5993)
Using `FxHashMap` is faster than `HashMap` in many cases, especially for hashing-heavy workloads. This change improves the performance of the linter, prettier, and diagnostics crates by using `FxHashMap` instead of `std::collections::HashMap`.
1 parent b240b42 commit 2b17003

17 files changed

+67
-62
lines changed
 

‎Cargo.lock

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎crates/oxc_diagnostics/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,6 @@ doctest = false
2222
miette = { workspace = true }
2323

2424
owo-colors = { workspace = true }
25+
rustc-hash = { workspace = true }
2526
textwrap = { workspace = true }
2627
unicode-width = { workspace = true }

‎crates/oxc_diagnostics/src/reporter/checkstyle.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
use std::{borrow::Cow, collections::HashMap};
1+
use std::borrow::Cow;
22

33
use super::{DiagnosticReporter, Info};
44
use crate::{Error, Severity};
5+
use rustc_hash::FxHashMap;
56

67
#[derive(Default)]
78
pub struct CheckstyleReporter {
@@ -24,7 +25,7 @@ impl DiagnosticReporter for CheckstyleReporter {
2425
#[allow(clippy::print_stdout)]
2526
fn format_checkstyle(diagnostics: &[Error]) {
2627
let infos = diagnostics.iter().map(Info::new).collect::<Vec<_>>();
27-
let mut grouped: HashMap<String, Vec<Info>> = HashMap::new();
28+
let mut grouped: FxHashMap<String, Vec<Info>> = FxHashMap::default();
2829
for info in infos {
2930
grouped.entry(info.filename.clone()).or_default().push(info);
3031
}

‎crates/oxc_linter/src/rules/eslint/no_this_before_super.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::collections::{HashMap, HashSet};
1+
use std::collections::HashSet;
22

33
use oxc_ast::{
44
ast::{Argument, Expression, MethodDefinitionKind},
@@ -12,6 +12,7 @@ use oxc_diagnostics::OxcDiagnostic;
1212
use oxc_macros::declare_oxc_lint;
1313
use oxc_semantic::NodeId;
1414
use oxc_span::{GetSpan, Span};
15+
use rustc_hash::FxHashMap;
1516

1617
use crate::{context::LintContext, rule::Rule, AstNode};
1718

@@ -62,7 +63,8 @@ impl Rule for NoThisBeforeSuper {
6263
// first pass -> find super calls and local violations
6364
let mut wanted_nodes = Vec::new();
6465
let mut basic_blocks_with_super_called = HashSet::<BasicBlockId>::new();
65-
let mut basic_blocks_with_local_violations = HashMap::<BasicBlockId, Vec<NodeId>>::new();
66+
let mut basic_blocks_with_local_violations =
67+
FxHashMap::<BasicBlockId, Vec<NodeId>>::default();
6668
for node in semantic.nodes() {
6769
match node.kind() {
6870
AstKind::Function(_) | AstKind::ArrowFunctionExpression(_) => {
@@ -153,7 +155,7 @@ impl NoThisBeforeSuper {
153155
cfg: &ControlFlowGraph,
154156
id: BasicBlockId,
155157
basic_blocks_with_super_called: &HashSet<BasicBlockId>,
156-
basic_blocks_with_local_violations: &HashMap<BasicBlockId, Vec<NodeId>>,
158+
basic_blocks_with_local_violations: &FxHashMap<BasicBlockId, Vec<NodeId>>,
157159
follow_join: bool,
158160
) -> Vec<DefinitelyCallsThisBeforeSuper> {
159161
neighbors_filtered_by_edge_weight(
@@ -212,7 +214,7 @@ impl NoThisBeforeSuper {
212214
cfg: &ControlFlowGraph,
213215
output: Vec<DefinitelyCallsThisBeforeSuper>,
214216
basic_blocks_with_super_called: &HashSet<BasicBlockId>,
215-
basic_blocks_with_local_violations: &HashMap<BasicBlockId, Vec<NodeId>>,
217+
basic_blocks_with_local_violations: &FxHashMap<BasicBlockId, Vec<NodeId>>,
216218
) -> bool {
217219
// Deciding whether we definitely call this before super in all
218220
// codepaths is as simple as seeing if any individual codepath

‎crates/oxc_linter/src/rules/jest/no_confusing_set_timeout.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
use std::collections::HashMap;
2-
31
use cow_utils::CowUtils;
42
use oxc_ast::{ast::MemberExpression, AstKind};
53
use oxc_diagnostics::OxcDiagnostic;
64
use oxc_macros::declare_oxc_lint;
75
use oxc_semantic::{AstNode, NodeId, ReferenceId};
86
use oxc_span::{GetSpan, Span};
7+
use rustc_hash::FxHashMap;
98

109
use crate::{
1110
context::LintContext,
@@ -80,10 +79,11 @@ impl Rule for NoConfusingSetTimeout {
8079
let scopes = ctx.scopes();
8180
let symbol_table = ctx.symbols();
8281
let possible_nodes = collect_possible_jest_call_node(ctx);
83-
let id_to_jest_node_map = possible_nodes.iter().fold(HashMap::new(), |mut acc, cur| {
84-
acc.insert(cur.node.id(), cur);
85-
acc
86-
});
82+
let id_to_jest_node_map =
83+
possible_nodes.iter().fold(FxHashMap::default(), |mut acc, cur| {
84+
acc.insert(cur.node.id(), cur);
85+
acc
86+
});
8787

8888
let mut jest_reference_id_list: Vec<(ReferenceId, Span)> = vec![];
8989
let mut seen_jest_set_timeout = false;
@@ -151,7 +151,7 @@ fn handle_jest_set_time_out<'a>(
151151
reference_id_list: impl Iterator<Item = ReferenceId>,
152152
jest_reference_id_list: &Vec<(ReferenceId, Span)>,
153153
seen_jest_set_timeout: &mut bool,
154-
id_to_jest_node_map: &HashMap<NodeId, &PossibleJestNode<'a, '_>>,
154+
id_to_jest_node_map: &FxHashMap<NodeId, &PossibleJestNode<'a, '_>>,
155155
) {
156156
let nodes = ctx.nodes();
157157
let scopes = ctx.scopes();
@@ -199,7 +199,7 @@ fn handle_jest_set_time_out<'a>(
199199

200200
fn is_jest_fn_call<'a>(
201201
parent_node: &AstNode<'a>,
202-
id_to_jest_node_map: &HashMap<NodeId, &PossibleJestNode<'a, '_>>,
202+
id_to_jest_node_map: &FxHashMap<NodeId, &PossibleJestNode<'a, '_>>,
203203
ctx: &LintContext<'a>,
204204
) -> bool {
205205
let mut id = parent_node.id();

‎crates/oxc_linter/src/rules/jest/no_duplicate_hooks.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
use std::collections::HashMap;
2-
31
use oxc_ast::AstKind;
42
use oxc_diagnostics::OxcDiagnostic;
53
use oxc_macros::declare_oxc_lint;
64
use oxc_semantic::NodeId;
75
use oxc_span::Span;
6+
use rustc_hash::FxHashMap;
87

98
use crate::{
109
context::LintContext,
@@ -104,7 +103,8 @@ impl Rule for NoDuplicateHooks {
104103
let Some(root_node) = ctx.nodes().root_node() else {
105104
return;
106105
};
107-
let mut hook_contexts: HashMap<NodeId, Vec<HashMap<String, i32>>> = HashMap::new();
106+
let mut hook_contexts: FxHashMap<NodeId, Vec<FxHashMap<String, i32>>> =
107+
FxHashMap::default();
108108
hook_contexts.insert(root_node.id(), Vec::new());
109109

110110
let mut possibles_jest_nodes = collect_possible_jest_call_node(ctx);
@@ -120,7 +120,7 @@ impl NoDuplicateHooks {
120120
fn run<'a>(
121121
possible_jest_node: &PossibleJestNode<'a, '_>,
122122
root_node_id: NodeId,
123-
hook_contexts: &mut HashMap<NodeId, Vec<HashMap<String, i32>>>,
123+
hook_contexts: &mut FxHashMap<NodeId, Vec<FxHashMap<String, i32>>>,
124124
ctx: &LintContext<'a>,
125125
) {
126126
let node = possible_jest_node.node;
@@ -157,7 +157,7 @@ impl NoDuplicateHooks {
157157
let last_context = if let Some(val) = contexts.last_mut() {
158158
Some(val)
159159
} else {
160-
let mut context = HashMap::new();
160+
let mut context = FxHashMap::default();
161161
context.insert(hook_name.clone(), 0);
162162
contexts.push(context);
163163
contexts.last_mut()

‎crates/oxc_linter/src/rules/jest/no_identical_title.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use std::collections::HashMap;
2-
31
use oxc_ast::{
42
ast::{Argument, CallExpression},
53
AstKind,
@@ -8,6 +6,7 @@ use oxc_diagnostics::OxcDiagnostic;
86
use oxc_macros::declare_oxc_lint;
97
use oxc_semantic::NodeId;
108
use oxc_span::Span;
9+
use rustc_hash::FxHashMap;
1110

1211
use crate::{
1312
context::LintContext,
@@ -74,8 +73,8 @@ declare_oxc_lint!(
7473
impl Rule for NoIdenticalTitle {
7574
fn run_once(&self, ctx: &LintContext) {
7675
let possible_jest_nodes = collect_possible_jest_call_node(ctx);
77-
let mut title_to_span_mapping = HashMap::new();
78-
let mut span_to_parent_mapping = HashMap::new();
76+
let mut title_to_span_mapping = FxHashMap::default();
77+
let mut span_to_parent_mapping = FxHashMap::default();
7978

8079
possible_jest_nodes
8180
.iter()

‎crates/oxc_linter/src/rules/jest/no_standalone_expect.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
use std::collections::HashMap;
2-
31
use oxc_ast::AstKind;
42
use oxc_diagnostics::OxcDiagnostic;
53
use oxc_macros::declare_oxc_lint;
64
use oxc_semantic::NodeId;
75
use oxc_span::Span;
6+
use rustc_hash::FxHashMap;
87

98
use crate::{
109
context::LintContext,
@@ -76,10 +75,11 @@ impl Rule for NoStandaloneExpect {
7675

7776
fn run_once(&self, ctx: &LintContext<'_>) {
7877
let possible_jest_nodes = collect_possible_jest_call_node(ctx);
79-
let id_nodes_mapping = possible_jest_nodes.iter().fold(HashMap::new(), |mut acc, cur| {
80-
acc.entry(cur.node.id()).or_insert(cur);
81-
acc
82-
});
78+
let id_nodes_mapping =
79+
possible_jest_nodes.iter().fold(FxHashMap::default(), |mut acc, cur| {
80+
acc.entry(cur.node.id()).or_insert(cur);
81+
acc
82+
});
8383

8484
for possible_jest_node in &possible_jest_nodes {
8585
self.run(possible_jest_node, &id_nodes_mapping, ctx);
@@ -91,7 +91,7 @@ impl NoStandaloneExpect {
9191
fn run<'a>(
9292
&self,
9393
possible_jest_node: &PossibleJestNode<'a, '_>,
94-
id_nodes_mapping: &HashMap<NodeId, &PossibleJestNode<'a, '_>>,
94+
id_nodes_mapping: &FxHashMap<NodeId, &PossibleJestNode<'a, '_>>,
9595
ctx: &LintContext<'a>,
9696
) {
9797
let node = possible_jest_node.node;
@@ -129,7 +129,7 @@ impl NoStandaloneExpect {
129129
fn is_correct_place_to_call_expect<'a>(
130130
node: &AstNode<'a>,
131131
additional_test_block_functions: &[String],
132-
id_nodes_mapping: &HashMap<NodeId, &PossibleJestNode<'a, '_>>,
132+
id_nodes_mapping: &FxHashMap<NodeId, &PossibleJestNode<'a, '_>>,
133133
ctx: &LintContext<'a>,
134134
) -> Option<()> {
135135
let mut parent = ctx.nodes().parent_node(node.id())?;
@@ -197,7 +197,7 @@ fn is_correct_place_to_call_expect<'a>(
197197
fn is_var_declarator_or_test_block<'a>(
198198
node: &AstNode<'a>,
199199
additional_test_block_functions: &[String],
200-
id_nodes_mapping: &HashMap<NodeId, &PossibleJestNode<'a, '_>>,
200+
id_nodes_mapping: &FxHashMap<NodeId, &PossibleJestNode<'a, '_>>,
201201
ctx: &LintContext<'a>,
202202
) -> bool {
203203
match node.kind() {

‎crates/oxc_linter/src/rules/jest/prefer_hooks_on_top.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
use std::collections::HashMap;
2-
31
use oxc_ast::AstKind;
42
use oxc_diagnostics::OxcDiagnostic;
53
use oxc_macros::declare_oxc_lint;
64
use oxc_semantic::ScopeId;
75
use oxc_span::Span;
6+
use rustc_hash::FxHashMap;
87

98
use crate::{
109
context::LintContext,
@@ -141,7 +140,7 @@ declare_oxc_lint!(
141140

142141
impl Rule for PreferHooksOnTop {
143142
fn run_once(&self, ctx: &LintContext) {
144-
let mut hooks_contexts: HashMap<ScopeId, bool> = HashMap::default();
143+
let mut hooks_contexts: FxHashMap<ScopeId, bool> = FxHashMap::default();
145144
let mut possibles_jest_nodes = collect_possible_jest_call_node(ctx);
146145
possibles_jest_nodes.sort_by_key(|n| n.node.id());
147146

@@ -154,7 +153,7 @@ impl Rule for PreferHooksOnTop {
154153
impl PreferHooksOnTop {
155154
fn run<'a>(
156155
possible_jest_node: &PossibleJestNode<'a, '_>,
157-
hooks_context: &mut HashMap<ScopeId, bool>,
156+
hooks_context: &mut FxHashMap<ScopeId, bool>,
158157
ctx: &LintContext<'a>,
159158
) {
160159
let node = possible_jest_node.node;

‎crates/oxc_linter/src/rules/jest/require_top_level_describe.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
use std::collections::HashMap;
2-
31
use oxc_ast::AstKind;
42
use oxc_diagnostics::OxcDiagnostic;
53
use oxc_macros::declare_oxc_lint;
64
use oxc_semantic::ScopeId;
75
use oxc_span::Span;
6+
use rustc_hash::FxHashMap;
87

98
use crate::{
109
context::LintContext,
@@ -123,7 +122,7 @@ impl Rule for RequireTopLevelDescribe {
123122
}
124123

125124
fn run_once(&self, ctx: &LintContext) {
126-
let mut describe_contexts: HashMap<ScopeId, usize> = HashMap::new();
125+
let mut describe_contexts: FxHashMap<ScopeId, usize> = FxHashMap::default();
127126
let mut possibles_jest_nodes = collect_possible_jest_call_node(ctx);
128127
possibles_jest_nodes.sort_by_key(|n| n.node.id());
129128

@@ -137,7 +136,7 @@ impl RequireTopLevelDescribe {
137136
fn run<'a>(
138137
&self,
139138
possible_jest_node: &PossibleJestNode<'a, '_>,
140-
describe_contexts: &mut HashMap<ScopeId, usize>,
139+
describe_contexts: &mut FxHashMap<ScopeId, usize>,
141140
ctx: &LintContext<'a>,
142141
) {
143142
let node = possible_jest_node.node;

‎crates/oxc_linter/src/rules/jest/valid_title.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{collections::HashMap, hash::Hash};
1+
use std::hash::Hash;
22

33
use cow_utils::CowUtils;
44
use oxc_ast::{
@@ -9,6 +9,7 @@ use oxc_diagnostics::OxcDiagnostic;
99
use oxc_macros::declare_oxc_lint;
1010
use oxc_span::{GetSpan, Span};
1111
use regex::Regex;
12+
use rustc_hash::FxHashMap;
1213

1314
use crate::{
1415
context::LintContext,
@@ -31,8 +32,8 @@ pub struct ValidTitleConfig {
3132
ignore_type_of_describe_name: bool,
3233
disallowed_words: Vec<String>,
3334
ignore_space: bool,
34-
must_not_match_patterns: HashMap<MatchKind, CompiledMatcherAndMessage>,
35-
must_match_patterns: HashMap<MatchKind, CompiledMatcherAndMessage>,
35+
must_not_match_patterns: FxHashMap<MatchKind, CompiledMatcherAndMessage>,
36+
must_match_patterns: FxHashMap<MatchKind, CompiledMatcherAndMessage>,
3637
}
3738

3839
impl std::ops::Deref for ValidTitle {
@@ -206,14 +207,14 @@ impl MatchKind {
206207

207208
fn compile_matcher_patterns(
208209
matcher_patterns: &serde_json::Value,
209-
) -> Option<HashMap<MatchKind, CompiledMatcherAndMessage>> {
210+
) -> Option<FxHashMap<MatchKind, CompiledMatcherAndMessage>> {
210211
matcher_patterns
211212
.as_array()
212213
.map_or_else(
213214
|| {
214215
// for `{ "describe": "/pattern/" }`
215216
let obj = matcher_patterns.as_object()?;
216-
let mut map: HashMap<MatchKind, CompiledMatcherAndMessage> = HashMap::new();
217+
let mut map: FxHashMap<MatchKind, CompiledMatcherAndMessage> = FxHashMap::default();
217218
for (key, value) in obj {
218219
let Some(v) = compile_matcher_pattern(MatcherPattern::String(value)) else {
219220
continue;
@@ -227,7 +228,7 @@ fn compile_matcher_patterns(
227228
},
228229
|value| {
229230
// for `["/pattern/", "message"]`
230-
let mut map: HashMap<MatchKind, CompiledMatcherAndMessage> = HashMap::new();
231+
let mut map: FxHashMap<MatchKind, CompiledMatcherAndMessage> = FxHashMap::default();
231232
let v = &compile_matcher_pattern(MatcherPattern::Vec(value))?;
232233
map.insert(MatchKind::Describe, v.clone());
233234
map.insert(MatchKind::Test, v.clone());
@@ -239,7 +240,7 @@ fn compile_matcher_patterns(
239240
|| {
240241
// for `"/pattern/"`
241242
let string = matcher_patterns.as_str()?;
242-
let mut map: HashMap<MatchKind, CompiledMatcherAndMessage> = HashMap::new();
243+
let mut map: FxHashMap<MatchKind, CompiledMatcherAndMessage> = FxHashMap::default();
243244
let v = &compile_matcher_pattern(MatcherPattern::String(
244245
&serde_json::Value::String(string.to_string()),
245246
))?;

‎crates/oxc_linter/src/rules/react/no_unknown_property.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{borrow::Cow, collections::hash_map::HashMap};
1+
use std::borrow::Cow;
22

33
use cow_utils::CowUtils;
44
use itertools::Itertools;
@@ -12,7 +12,7 @@ use oxc_macros::declare_oxc_lint;
1212
use oxc_span::{GetSpan, Span};
1313
use phf::{phf_map, phf_set, Map, Set};
1414
use regex::Regex;
15-
use rustc_hash::FxHashSet;
15+
use rustc_hash::{FxHashMap, FxHashSet};
1616
use serde::Deserialize;
1717

1818
use crate::{
@@ -426,11 +426,11 @@ const DOM_PROPERTIES_IGNORE_CASE: [&str; 5] = [
426426
"webkitDirectory",
427427
];
428428

429-
static DOM_PROPERTIES_LOWER_MAP: Lazy<HashMap<String, &'static str>> = Lazy::new(|| {
429+
static DOM_PROPERTIES_LOWER_MAP: Lazy<FxHashMap<String, &'static str>> = Lazy::new(|| {
430430
DOM_PROPERTIES_NAMES
431431
.iter()
432432
.map(|it| (it.cow_to_lowercase().into_owned(), *it))
433-
.collect::<HashMap<_, _>>()
433+
.collect::<FxHashMap<_, _>>()
434434
});
435435

436436
///

‎crates/oxc_linter/src/rules/typescript/triple_slash_reference.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
use std::collections::HashMap;
2-
31
use oxc_ast::{
42
ast::{Statement, TSModuleReference},
53
AstKind,
64
};
75
use oxc_diagnostics::OxcDiagnostic;
86
use oxc_macros::declare_oxc_lint;
97
use oxc_span::{GetSpan, Span};
8+
use rustc_hash::FxHashMap;
109

1110
use crate::{
1211
context::{ContextHost, LintContext},
@@ -113,7 +112,7 @@ impl Rule for TripleSlashReference {
113112
// We don't need to iterate over all comments since Triple-slash directives are only valid at the top of their containing file.
114113
// We are trying to get the first statement start potioin, falling back to the program end if statement does not exist
115114
let comments_range_end = program.body.first().map_or(program.span.end, |v| v.span().start);
116-
let mut refs_for_import = HashMap::new();
115+
let mut refs_for_import = FxHashMap::default();
117116

118117
for comment in ctx.semantic().trivias().comments_range(0..comments_range_end) {
119118
let raw = &ctx.semantic().source_text()

‎crates/oxc_linter/src/service.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use std::{
2-
collections::HashMap,
32
ffi::OsStr,
43
fs,
54
path::{Path, PathBuf},
@@ -15,7 +14,7 @@ use oxc_resolver::Resolver;
1514
use oxc_semantic::{ModuleRecord, SemanticBuilder};
1615
use oxc_span::{SourceType, VALID_EXTENSIONS};
1716
use rayon::{iter::ParallelBridge, prelude::ParallelIterator};
18-
use rustc_hash::FxHashSet;
17+
use rustc_hash::{FxHashMap, FxHashSet};
1918

2019
use crate::{
2120
partial_loader::{JavaScriptSource, PartialLoader, LINT_PARTIAL_LOADER_EXT},
@@ -145,7 +144,7 @@ impl LintService {
145144
///
146145
/// See the "problem section" in <https://medium.com/@polyglot_factotum/rust-concurrency-patterns-condvars-and-locks-e278f18db74f>
147146
/// and the solution is copied here to fix the issue.
148-
type CacheState = Mutex<HashMap<Box<Path>, Arc<(Mutex<CacheStateEntry>, Condvar)>>>;
147+
type CacheState = Mutex<FxHashMap<Box<Path>, Arc<(Mutex<CacheStateEntry>, Condvar)>>>;
149148

150149
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
151150
enum CacheStateEntry {

‎crates/oxc_prettier/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ oxc_syntax = { workspace = true }
2727

2828
bitflags = { workspace = true }
2929
cow-utils = { workspace = true }
30+
rustc-hash = { workspace = true }
3031

3132
[dev-dependencies]
3233
oxc_parser = { workspace = true }

‎crates/oxc_prettier/src/printer/mod.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
66
mod command;
77

8-
use std::collections::{HashMap, VecDeque};
8+
use std::collections::VecDeque;
99

1010
use oxc_allocator::Allocator;
11+
use rustc_hash::FxHashMap;
1112

1213
use self::command::{Command, Indent, Mode};
1314
use crate::{
@@ -27,7 +28,7 @@ pub struct Printer<'a> {
2728
cmds: Vec<Command<'a>>,
2829

2930
line_suffix: Vec<Command<'a>>,
30-
group_mode_map: HashMap<GroupId, Mode>,
31+
group_mode_map: FxHashMap<GroupId, Mode>,
3132

3233
// states
3334
new_line: &'static str,
@@ -59,7 +60,7 @@ impl<'a> Printer<'a> {
5960
pos: 0,
6061
cmds,
6162
line_suffix: vec![],
62-
group_mode_map: HashMap::new(),
63+
group_mode_map: FxHashMap::default(),
6364
new_line: options.end_of_line.as_str(),
6465
allocator,
6566
}

‎crates/oxc_semantic/examples/cfg.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#![allow(clippy::print_stdout)]
2-
use std::{collections::HashMap, env, path::Path, sync::Arc};
2+
use std::{env, path::Path, sync::Arc};
33

44
use itertools::Itertools;
55
use oxc_allocator::Allocator;
@@ -13,6 +13,7 @@ use oxc_cfg::{
1313
use oxc_parser::Parser;
1414
use oxc_semantic::{dot::DebugDot, SemanticBuilder};
1515
use oxc_span::SourceType;
16+
use rustc_hash::FxHashMap;
1617

1718
// Instruction:
1819
// 1. create a `test.js`,
@@ -76,7 +77,7 @@ fn main() -> std::io::Result<()> {
7677
.cfg()
7778
.expect("we set semantic to build the control flow (`with_cfg`) for us so it should always be `Some`");
7879

79-
let mut ast_nodes_by_block = HashMap::<_, Vec<_>>::new();
80+
let mut ast_nodes_by_block = FxHashMap::<_, Vec<_>>::default();
8081
for node in semantic.semantic.nodes() {
8182
let block = node.cfg_id();
8283
let block_ix = cfg.graph.node_weight(block).unwrap();

0 commit comments

Comments
 (0)
Please sign in to comment.