diff --git a/Cargo.lock b/Cargo.lock index 8497a16d614e..924c9c3a7552 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1735,6 +1735,7 @@ dependencies = [ "rome_markup", "rome_rowan", "rust-lapper", + "rustc-hash", ] [[package]] diff --git a/crates/rome_js_semantic/Cargo.toml b/crates/rome_js_semantic/Cargo.toml index b1d05bb59ffa..a181b2d2d878 100644 --- a/crates/rome_js_semantic/Cargo.toml +++ b/crates/rome_js_semantic/Cargo.toml @@ -11,6 +11,7 @@ repository = "https://github.com/rome/tools" rome_rowan = { path = "../rome_rowan" } rome_js_syntax = { path = "../rome_js_syntax" } rust-lapper = "1.0.1" +rustc-hash = { workspace = true } [dev-dependencies] rome_markup = { path = "../rome_markup" } diff --git a/crates/rome_js_semantic/src/events.rs b/crates/rome_js_semantic/src/events.rs index 05536d9c2e37..0eb5f725a8d3 100644 --- a/crates/rome_js_semantic/src/events.rs +++ b/crates/rome_js_semantic/src/events.rs @@ -1,5 +1,6 @@ //! Events emitted by the [SemanticEventExtractor] which are then constructed into the Semantic Model +use rustc_hash::FxHashMap; use std::collections::{HashMap, VecDeque}; use rome_js_syntax::{ @@ -158,7 +159,7 @@ pub struct SemanticEventExtractor { stash: VecDeque, scopes: Vec, next_scope_id: usize, - bindings: HashMap, + bindings: FxHashMap, } #[derive(Debug)] @@ -233,7 +234,7 @@ impl SemanticEventExtractor { stash: VecDeque::new(), scopes: vec![], next_scope_id: 0, - bindings: HashMap::new(), + bindings: FxHashMap::default(), } } diff --git a/crates/rome_js_semantic/src/semantic_model.rs b/crates/rome_js_semantic/src/semantic_model.rs index b010121f9bea..935c5e28e2d4 100644 --- a/crates/rome_js_semantic/src/semantic_model.rs +++ b/crates/rome_js_semantic/src/semantic_model.rs @@ -10,8 +10,9 @@ use rome_js_syntax::{ }; use rome_rowan::{AstNode, SyntaxTokenText}; use rust_lapper::{Interval, Lapper}; +use rustc_hash::{FxHashMap, FxHashSet}; use std::{ - collections::{BTreeSet, HashMap, HashSet, VecDeque}, + collections::{BTreeSet, HashSet, VecDeque}, iter::FusedIterator, sync::Arc, }; @@ -112,7 +113,7 @@ struct SemanticModelScopeData { // All bindings of this scope bindings: Vec, // Map pointing to the [bindings] vec of each bindings by its name - bindings_by_name: HashMap, + bindings_by_name: FxHashMap, // All read references of a scope read_references: Vec, // All write references of a scope @@ -130,19 +131,19 @@ struct SemanticModelData { scopes: Vec, scope_by_range: rust_lapper::Lapper, // Maps the start of a node range to a scope id - scope_hoisted_to_by_range: HashMap, + scope_hoisted_to_by_range: FxHashMap, // Map to each by its range - node_by_range: HashMap, + node_by_range: FxHashMap, // Maps any range in the code to its declaration - declared_at_by_range: HashMap, + declared_at_by_range: FxHashMap, // Maps a declaration range to the range of its references - declaration_all_references: HashMap>, + declaration_all_references: FxHashMap>, // Maps a declaration range to the range of its "reads" - declaration_all_reads: HashMap>, + declaration_all_reads: FxHashMap>, // Maps a declaration range to the range of its "writes" - declaration_all_writes: HashMap>, + declaration_all_writes: FxHashMap>, // All bindings that were exported - exported: HashSet, + exported: FxHashSet, /// All references that could not be resolved unresolved_references: Vec<(ReferenceType, TextRange)>, /// All references that are resolved to globals @@ -335,7 +336,7 @@ impl Scope { } /// Return the [Closure] associated with this scope if - /// it has one, otherwise returns None. + /// it has one, otherwise returns None. /// See [HasClosureAstNode] for nodes that have closure. pub fn closure(&self) -> Option { Closure::from_scope(self.data.clone(), self.id, self.range()) @@ -882,16 +883,16 @@ impl ClosureExtensions for T {} /// and stored inside the [SemanticModel]. pub struct SemanticModelBuilder { root: JsAnyRoot, - node_by_range: HashMap, - globals: HashSet, + node_by_range: FxHashMap, + globals: FxHashSet, scopes: Vec, - scope_range_by_start: HashMap>>, - scope_hoisted_to_by_range: HashMap, - declarations_by_range: HashMap, - declaration_all_references: HashMap>, - declaration_all_reads: HashMap>, - declaration_all_writes: HashMap>, - exported: HashSet, + scope_range_by_start: FxHashMap>>, + scope_hoisted_to_by_range: FxHashMap, + declarations_by_range: FxHashMap, + declaration_all_references: FxHashMap>, + declaration_all_reads: FxHashMap>, + declaration_all_writes: FxHashMap>, + exported: FxHashSet, unresolved_references: Vec<(ReferenceType, TextRange)>, global_references: Vec<(ReferenceType, TextRange)>, } @@ -900,16 +901,16 @@ impl SemanticModelBuilder { pub fn new(root: JsAnyRoot) -> Self { Self { root, - node_by_range: HashMap::new(), - globals: HashSet::new(), + node_by_range: FxHashMap::default(), + globals: FxHashSet::default(), scopes: vec![], - scope_range_by_start: HashMap::new(), - scope_hoisted_to_by_range: HashMap::new(), - declarations_by_range: HashMap::new(), - declaration_all_references: HashMap::new(), - declaration_all_reads: HashMap::new(), - declaration_all_writes: HashMap::new(), - exported: HashSet::new(), + scope_range_by_start: FxHashMap::default(), + scope_hoisted_to_by_range: FxHashMap::default(), + declarations_by_range: FxHashMap::default(), + declaration_all_references: FxHashMap::default(), + declaration_all_reads: FxHashMap::default(), + declaration_all_writes: FxHashMap::default(), + exported: FxHashSet::default(), unresolved_references: Vec::new(), global_references: Vec::new(), } @@ -942,7 +943,7 @@ impl SemanticModelBuilder { parent: parent_scope_id, children: vec![], bindings: vec![], - bindings_by_name: HashMap::new(), + bindings_by_name: FxHashMap::default(), read_references: vec![], write_references: vec![], });