Skip to content

Commit

Permalink
perf(semantic): reduce lookups (#4214)
Browse files Browse the repository at this point in the history
Small performance optimization (I hope) to resolving references in `Semantic`. Look up current bindings once rather than on every turn of the loop.
  • Loading branch information
overlookmotel committed Jul 12, 2024
1 parent f23e54f commit ef4c1f4
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion crates/oxc_semantic/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,10 +380,11 @@ impl<'a> SemanticBuilder<'a> {
let parent_refs = iter.nth(self.current_scope_depth - 1).unwrap();
let current_refs = iter.next().unwrap();

let bindings = self.scope.get_bindings(self.current_scope_id);
for (name, reference_ids) in current_refs.drain() {
// Try to resolve a reference.
// If unresolved, transfer it to parent scope's unresolved references.
if let Some(symbol_id) = self.scope.get_binding(self.current_scope_id, &name) {
if let Some(symbol_id) = bindings.get(&name).copied() {
for reference_id in &reference_ids {
self.symbols.references[*reference_id].set_symbol_id(symbol_id);
}
Expand Down

0 comments on commit ef4c1f4

Please sign in to comment.