@@ -26,6 +26,11 @@ use crate::target::Target;
2626use crate :: types:: { MemberInfo , TypeId , TypeKind , TypeModifiers , TypeTable } ;
2727use std:: collections:: HashMap ;
2828
29+ /// Default capacity for variable mapping HashMaps during IR linearization
30+ const DEFAULT_VAR_MAP_CAPACITY : usize = 64 ;
31+ /// Default capacity for label/static HashMaps (typically smaller)
32+ const DEFAULT_LABEL_MAP_CAPACITY : usize = 16 ;
33+
2934/// Information about a local variable
3035#[ derive( Clone ) ]
3136struct LocalVarInfo {
@@ -127,9 +132,9 @@ impl<'a> Linearizer<'a> {
127132 current_bb : None ,
128133 next_pseudo : 0 ,
129134 next_bb : 0 ,
130- var_map : HashMap :: new ( ) ,
131- locals : HashMap :: new ( ) ,
132- label_map : HashMap :: new ( ) ,
135+ var_map : HashMap :: with_capacity ( DEFAULT_VAR_MAP_CAPACITY ) ,
136+ locals : HashMap :: with_capacity ( DEFAULT_VAR_MAP_CAPACITY ) ,
137+ label_map : HashMap :: with_capacity ( DEFAULT_LABEL_MAP_CAPACITY ) ,
133138 break_targets : Vec :: new ( ) ,
134139 continue_targets : Vec :: new ( ) ,
135140 run_ssa : true , // Enable SSA conversion by default
@@ -142,7 +147,7 @@ impl<'a> Linearizer<'a> {
142147 current_func_name : String :: new ( ) ,
143148 static_local_counter : 0 ,
144149 compound_literal_counter : 0 ,
145- static_locals : HashMap :: new ( ) ,
150+ static_locals : HashMap :: with_capacity ( DEFAULT_LABEL_MAP_CAPACITY ) ,
146151 current_pos : None ,
147152 target,
148153 current_func_is_non_static_inline : false ,
@@ -833,9 +838,11 @@ impl<'a> Linearizer<'a> {
833838 // Add parameters
834839 // For struct/union parameters, we need to copy them to local storage
835840 // so member access works properly
836- let mut struct_params: Vec < ( String , TypeId , PseudoId ) > = Vec :: new ( ) ;
841+ let mut struct_params: Vec < ( String , TypeId , PseudoId ) > =
842+ Vec :: with_capacity ( func. params . len ( ) ) ;
837843 // Complex parameters also need local storage for real/imag access
838- let mut complex_params: Vec < ( String , TypeId , PseudoId ) > = Vec :: new ( ) ;
844+ let mut complex_params: Vec < ( String , TypeId , PseudoId ) > =
845+ Vec :: with_capacity ( func. params . len ( ) ) ;
839846
840847 for ( i, param) in func. params . iter ( ) . enumerate ( ) {
841848 let name = param
0 commit comments