Some obvious evm & uint optimizations (#1576)

* fix name and tests for endians

* using renamed func

* zero and sign opt
This commit is contained in:
Nikolay Volf
2016-07-10 20:18:23 +02:00
committed by Gav Wood
parent d7caae2241
commit e15f631ec7
5 changed files with 62 additions and 20 deletions

View File

@@ -94,13 +94,7 @@ impl Memory for Vec<u8> {
fn write(&mut self, offset: U256, value: U256) {
let off = offset.low_u64() as usize;
let mut val = value;
let end = off + 32;
for pos in 0..32 {
self[end - pos - 1] = val.low_u64() as u8;
val = val >> 8;
}
value.to_big_endian(&mut self[off..off+32]);
}
fn write_byte(&mut self, offset: U256, value: U256) {

View File

@@ -303,9 +303,9 @@ impl<Cost: CostType> Interpreter<Cost> {
let out_size = stack.pop_back();
// Add stipend (only CALL|CALLCODE when value > 0)
let call_gas = call_gas + value.map_or_else(|| Cost::from(0), |val| match val > U256::zero() {
true => Cost::from(ext.schedule().call_stipend),
false => Cost::from(0)
let call_gas = call_gas + value.map_or_else(|| Cost::from(0), |val| match val.is_zero() {
false => Cost::from(ext.schedule().call_stipend),
true => Cost::from(0)
});
// Get sender & receive addresses, check if we have balance
@@ -550,7 +550,7 @@ impl<Cost: CostType> Interpreter<Cost> {
}
fn is_zero(&self, val: &U256) -> bool {
&U256::zero() == val
val.is_zero()
}
fn bool_to_u256(&self, val: bool) -> U256 {
@@ -782,7 +782,8 @@ impl<Cost: CostType> Interpreter<Cost> {
}
fn get_and_reset_sign(value: U256) -> (U256, bool) {
let sign = (value >> 255).low_u64() == 1;
let U256(arr) = value;
let sign = arr[3].leading_zeros() == 0;
(set_sign(value, sign), sign)
}