From 97082ca8079533ee82991340751323c4b2d430f4 Mon Sep 17 00:00:00 2001 From: arkpar Date: Fri, 5 Feb 2016 02:15:26 +0100 Subject: [PATCH] Reduced allocations in interpreter --- ethcore/src/evm/interpreter.rs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/ethcore/src/evm/interpreter.rs b/ethcore/src/evm/interpreter.rs index 6516d9946..6bec042cb 100644 --- a/ethcore/src/evm/interpreter.rs +++ b/ethcore/src/evm/interpreter.rs @@ -263,7 +263,7 @@ pub struct Interpreter; impl evm::Evm for Interpreter { fn exec(&self, params: ActionParams, ext: &mut evm::Ext) -> evm::Result { - let code = ¶ms.code.clone().unwrap(); + let code = ¶ms.code.as_ref().unwrap(); let valid_jump_destinations = self.find_jump_destinations(&code); let mut current_gas = params.gas.clone(); @@ -728,12 +728,15 @@ impl Interpreter { let big_id = stack.pop_back(); let id = big_id.low_u64() as usize; let max = id.wrapping_add(32); - let data = params.data.clone().unwrap_or_else(|| vec![]); - let bound = cmp::min(data.len(), max); - if id < bound && big_id < U256::from(data.len()) { - let mut v = data[id..bound].to_vec(); - v.resize(32, 0); - stack.push(U256::from(&v[..])) + if let Some(data) = params.data.as_ref() { + let bound = cmp::min(data.len(), max); + if id < bound && big_id < U256::from(data.len()) { + let mut v = [0u8; 32]; + v[0..bound-id].clone_from_slice(&data[id..bound]); + stack.push(U256::from(&v[..])) + } else { + stack.push(U256::zero()) + } } else { stack.push(U256::zero()) }