From 585bdac91ea9c3829f7e03114e2da3ec260af872 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Thu, 3 Jan 2019 14:08:31 -0800 Subject: [PATCH] Use `vec![0; size]` instead of creating an empty `Vec` and resizing. --- lib/jit/src/action.rs | 3 +-- lib/runtime/src/table.rs | 16 ++++------------ 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/lib/jit/src/action.rs b/lib/jit/src/action.rs index abbedde5e0..84a358a69e 100644 --- a/lib/jit/src/action.rs +++ b/lib/jit/src/action.rs @@ -158,9 +158,8 @@ pub fn invoke( // TODO: Support values larger than u64. And pack the values into memory // instead of just using fixed-sized slots. - let mut values_vec: Vec = Vec::new(); let value_size = mem::size_of::(); - values_vec.resize(max(signature.params.len(), signature.returns.len()), 0u64); + let mut values_vec: Vec = vec![0; max(signature.params.len(), signature.returns.len())]; // Store the argument values into `values_vec`. for (index, arg) in args.iter().enumerate() { diff --git a/lib/runtime/src/table.rs b/lib/runtime/src/table.rs index 62c6f5db36..f9dcf125d6 100644 --- a/lib/runtime/src/table.rs +++ b/lib/runtime/src/table.rs @@ -25,18 +25,10 @@ impl Table { }; match plan.style { - TableStyle::CallerChecksSignature => { - let mut vec = Vec::with_capacity(plan.table.minimum as usize); - vec.resize( - plan.table.minimum as usize, - VMCallerCheckedAnyfunc::default(), - ); - - Self { - vec, - maximum: plan.table.maximum, - } - } + TableStyle::CallerChecksSignature => Self { + vec: vec![VMCallerCheckedAnyfunc::default(); plan.table.minimum as usize], + maximum: plan.table.maximum, + }, } }