Skip to content

Commit

Permalink
refactor(semantic): do not reserve space in resolved_references (#4962
Browse files Browse the repository at this point in the history
)

While resolving references in `SemanticBuilder`, there is little benefit to reserving space in advance in `resolved_references` as it is not possible to avoid growing the `Vec`. The comment here says "Reserve space for all references to avoid reallocations", but `reserve()` itself may cause a reallocation.
  • Loading branch information
overlookmotel committed Aug 19, 2024
1 parent a7ef30d commit d677b8e
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions crates/oxc_semantic/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,10 +466,7 @@ impl<'a> SemanticBuilder<'a> {
if let Some(symbol_id) = bindings.get(name.as_str()).copied() {
let symbol_flag = self.symbols.get_flag(symbol_id);

let resolved_references: &mut Vec<_> =
self.symbols.resolved_references[symbol_id].as_mut();
// Reserve space for all references to avoid reallocations.
resolved_references.reserve(references.len());
let resolved_references = &mut self.symbols.resolved_references[symbol_id];

references.retain(|&reference_id| {
let reference = &mut self.symbols.references[reference_id];
Expand Down

0 comments on commit d677b8e

Please sign in to comment.