@@ -110,7 +110,7 @@ impl<'a> SemanticBuilder<'a> {
110110 // This is just an estimate of a good initial size, but certainly better than
111111 // `Vec`'s default initial capacity of 4.
112112 let mut unresolved_references = vec ! [ ] ;
113- unresolved_references. resize_with ( 16 , Default :: default) ;
113+ unresolved_references. resize_with ( 16 , UnresolvedReferences :: default) ;
114114
115115 let trivias = Trivias :: default ( ) ;
116116 Self {
@@ -481,11 +481,19 @@ impl<'a> Visit<'a> for SemanticBuilder<'a> {
481481 self . scope . get_bindings_mut ( self . current_scope_id ) . extend ( bindings) ;
482482 }
483483
484- // Increment scope depth, and ensure stack is large enough that
485- // `self.unresolved_references[self.current_scope_depth]` is initialized
484+ // Increment scope depth.
485+ // If stack is not large enough, double its size.
486+ // This ensures `self.unresolved_references[self.current_scope_depth]` is initialized.
487+ // We could just push a single entry to stack, but doubling growth strategy makes this branch
488+ // more consistently not taken, so can mark it `#[cold]`.
486489 self . current_scope_depth += 1 ;
487490 if self . unresolved_references . len ( ) <= self . current_scope_depth {
488- self . unresolved_references . push ( UnresolvedReferences :: default ( ) ) ;
491+ #[ cold]
492+ fn grow ( builder : & mut SemanticBuilder ) {
493+ let new_len = builder. unresolved_references . len ( ) * 2 ;
494+ builder. unresolved_references . resize_with ( new_len, UnresolvedReferences :: default) ;
495+ }
496+ grow ( self ) ;
489497 }
490498 }
491499
0 commit comments