Skip to content

Commit

Permalink
perf(traverse): optimize TraverseScoping::generate_uid_name
Browse files Browse the repository at this point in the history
  • Loading branch information
overlookmotel committed Oct 18, 2024
1 parent 9d43a11 commit d1f7b37
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions crates/oxc_traverse/src/context/scoping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ impl TraverseScoping {
pub fn generate_uid_name(&mut self, name: &str) -> CompactStr {
// If `uid_names` is not already populated, initialize it
if self.uid_names.is_none() {
self.init_uid_names();
self.uid_names = Some(self.init_uid_names());
}
let uid_names = self.uid_names.as_mut().unwrap();

Expand Down Expand Up @@ -413,9 +413,8 @@ impl TraverseScoping {
///
/// Once this map is created, generating a UID is a relatively quick operation, rather than
/// iterating over all symbols and unresolved references every time generate a UID.
fn init_uid_names(&mut self) {
let uid_names = self
.scopes
fn init_uid_names(&mut self) -> FxHashSet<CompactStr> {
self.scopes
.root_unresolved_references()
.keys()
.chain(self.symbols.names.iter())
Expand All @@ -426,8 +425,7 @@ impl TraverseScoping {
None
}
})
.collect();
self.uid_names = Some(uid_names);
.collect()
}
}

Expand Down

0 comments on commit d1f7b37

Please sign in to comment.