Skip to content

Commit

Permalink
perf(traverse): speed up finding UID binding name (#4356)
Browse files Browse the repository at this point in the history
Speed up finding UID var name. Previously iterated through all `SymbolTable::references` and checked each for a string match. Replace that with a single hashmap lookup on `ScopeTree::root_unresolved_references`.
  • Loading branch information
overlookmotel committed Jul 19, 2024
1 parent 4cd5df0 commit 7eb2864
Showing 1 changed file with 2 additions and 15 deletions.
17 changes: 2 additions & 15 deletions crates/oxc_traverse/src/context/scoping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -447,21 +447,8 @@ impl TraverseScoping {
}

fn name_is_unique(&self, name: &str) -> bool {
// Check if any bindings in program with this name
if self.symbols.names.iter().any(|n| n.as_str() == name) {
return false;
}

// Check for unbound references in program with this name
!self.symbols.references.iter().any(|reference| {
if reference.symbol_id().is_some() {
// Skip string comparison on bound references, as they'll also be in `symbols.names`
// which already checked above
false
} else {
reference.name().as_str() == name
}
})
!self.scopes.root_unresolved_references().contains_key(name)
&& !self.symbols.names.iter().any(|n| n.as_str() == name)
}
}

Expand Down

0 comments on commit 7eb2864

Please sign in to comment.