Use vec![0; size] instead of creating an empty Vec and resizing.

This commit is contained in:
Dan Gohman
2019-01-03 14:08:31 -08:00
parent a41bc1fe1e
commit 585bdac91e
2 changed files with 5 additions and 14 deletions

View File

@@ -158,9 +158,8 @@ pub fn invoke(
// TODO: Support values larger than u64. And pack the values into memory // TODO: Support values larger than u64. And pack the values into memory
// instead of just using fixed-sized slots. // instead of just using fixed-sized slots.
let mut values_vec: Vec<u64> = Vec::new();
let value_size = mem::size_of::<u64>(); let value_size = mem::size_of::<u64>();
values_vec.resize(max(signature.params.len(), signature.returns.len()), 0u64); let mut values_vec: Vec<u64> = vec![0; max(signature.params.len(), signature.returns.len())];
// Store the argument values into `values_vec`. // Store the argument values into `values_vec`.
for (index, arg) in args.iter().enumerate() { for (index, arg) in args.iter().enumerate() {

View File

@@ -25,18 +25,10 @@ impl Table {
}; };
match plan.style { match plan.style {
TableStyle::CallerChecksSignature => { TableStyle::CallerChecksSignature => Self {
let mut vec = Vec::with_capacity(plan.table.minimum as usize); vec: vec![VMCallerCheckedAnyfunc::default(); plan.table.minimum as usize],
vec.resize( maximum: plan.table.maximum,
plan.table.minimum as usize, },
VMCallerCheckedAnyfunc::default(),
);
Self {
vec,
maximum: plan.table.maximum,
}
}
} }
} }