Add a JumpTableData::with_capacity and use it.

As with Vec::with_capacity, this helps reduce intermediate heap allocation.
This commit is contained in:
Dan Gohman
2017-09-10 16:17:03 -07:00
parent 620f1f49e2
commit 47bc963ba5
2 changed files with 10 additions and 2 deletions

View File

@@ -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`.