Add a JumpTableData::with_capacity and use it.
As with Vec::with_capacity, this helps reduce intermediate heap allocation.
This commit is contained in:
@@ -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.
|
/// Set a table entry.
|
||||||
///
|
///
|
||||||
/// The table will grow as needed to fit `idx`.
|
/// The table will grow as needed to fit `idx`.
|
||||||
|
|||||||
@@ -364,7 +364,7 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
|
|||||||
if jump_args_count == 0 {
|
if jump_args_count == 0 {
|
||||||
// No jump arguments
|
// No jump arguments
|
||||||
let val = state.pop1();
|
let val = state.pop1();
|
||||||
let mut data = JumpTableData::new();
|
let mut data = JumpTableData::with_capacity(depths.len());
|
||||||
for depth in depths {
|
for depth in depths {
|
||||||
let i = state.control_stack.len() - 1 - (depth as usize);
|
let i = state.control_stack.len() - 1 - (depth as usize);
|
||||||
let frame = &mut state.control_stack[i];
|
let frame = &mut state.control_stack[i];
|
||||||
@@ -385,7 +385,7 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
|
|||||||
// We then proceed to split the edges going out of the br_table
|
// We then proceed to split the edges going out of the br_table
|
||||||
let val = state.pop1();
|
let val = state.pop1();
|
||||||
let cut_index = state.stack.len() - jump_args_count;
|
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<usize, Ebb> = depths.iter().fold(HashMap::new(), |mut acc,
|
let dest_ebbs: HashMap<usize, Ebb> = depths.iter().fold(HashMap::new(), |mut acc,
|
||||||
&depth| {
|
&depth| {
|
||||||
if acc.get(&(depth as usize)).is_none() {
|
if acc.get(&(depth as usize)).is_none() {
|
||||||
|
|||||||
Reference in New Issue
Block a user