Reduced allocations in interpreter
This commit is contained in:
		
							parent
							
								
									a87edc2557
								
							
						
					
					
						commit
						97082ca807
					
				@ -263,7 +263,7 @@ pub struct Interpreter;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
impl evm::Evm for Interpreter {
 | 
					impl evm::Evm for Interpreter {
 | 
				
			||||||
	fn exec(&self, params: ActionParams, ext: &mut evm::Ext) -> evm::Result {
 | 
						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 valid_jump_destinations = self.find_jump_destinations(&code);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		let mut current_gas = params.gas.clone();
 | 
							let mut current_gas = params.gas.clone();
 | 
				
			||||||
@ -728,15 +728,18 @@ impl Interpreter {
 | 
				
			|||||||
				let big_id = stack.pop_back();
 | 
									let big_id = stack.pop_back();
 | 
				
			||||||
				let id = big_id.low_u64() as usize;
 | 
									let id = big_id.low_u64() as usize;
 | 
				
			||||||
				let max = id.wrapping_add(32);
 | 
									let max = id.wrapping_add(32);
 | 
				
			||||||
				let data = params.data.clone().unwrap_or_else(|| vec![]);
 | 
									if let Some(data) = params.data.as_ref() {
 | 
				
			||||||
					let bound = cmp::min(data.len(), max);
 | 
										let bound = cmp::min(data.len(), max);
 | 
				
			||||||
					if id < bound && big_id < U256::from(data.len()) {
 | 
										if id < bound && big_id < U256::from(data.len()) {
 | 
				
			||||||
					let mut v = data[id..bound].to_vec();
 | 
											let mut v = [0u8; 32];
 | 
				
			||||||
					v.resize(32, 0);
 | 
											v[0..bound-id].clone_from_slice(&data[id..bound]);
 | 
				
			||||||
						stack.push(U256::from(&v[..]))
 | 
											stack.push(U256::from(&v[..]))
 | 
				
			||||||
					} else {
 | 
										} else {
 | 
				
			||||||
						stack.push(U256::zero())
 | 
											stack.push(U256::zero())
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
 | 
									} else {
 | 
				
			||||||
 | 
										stack.push(U256::zero())
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			instructions::CALLDATASIZE => {
 | 
								instructions::CALLDATASIZE => {
 | 
				
			||||||
				stack.push(U256::from(params.data.clone().map_or(0, |l| l.len())));
 | 
									stack.push(U256::from(params.data.clone().map_or(0, |l| l.len())));
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user