diff --git a/lib/cretonne/src/ir/jumptable.rs b/lib/cretonne/src/ir/jumptable.rs index 6d97341458..319eeb1edf 100644 --- a/lib/cretonne/src/ir/jumptable.rs +++ b/lib/cretonne/src/ir/jumptable.rs @@ -31,6 +31,14 @@ impl JumpTableData { } } + /// Create a new empty jump table with the specified capacity. + pub fn with_capacity(capacity: usize) -> JumpTableData { + JumpTableData { + table: Vec::with_capacity(capacity), + holes: 0, + } + } + /// Set a table entry. /// /// The table will grow as needed to fit `idx`. diff --git a/lib/wasm/src/code_translator.rs b/lib/wasm/src/code_translator.rs index 096d7d2b4d..ad099dc398 100644 --- a/lib/wasm/src/code_translator.rs +++ b/lib/wasm/src/code_translator.rs @@ -364,7 +364,7 @@ pub fn translate_operator( if jump_args_count == 0 { // No jump arguments let val = state.pop1(); - let mut data = JumpTableData::new(); + let mut data = JumpTableData::with_capacity(depths.len()); for depth in depths { let i = state.control_stack.len() - 1 - (depth as usize); let frame = &mut state.control_stack[i]; @@ -385,7 +385,7 @@ pub fn translate_operator( // We then proceed to split the edges going out of the br_table let val = state.pop1(); let cut_index = state.stack.len() - jump_args_count; - let mut data = JumpTableData::new(); + let mut data = JumpTableData::with_capacity(depths.len()); let dest_ebbs: HashMap = depths.iter().fold(HashMap::new(), |mut acc, &depth| { if acc.get(&(depth as usize)).is_none() {