Skip to content
This repository was archived by the owner on Nov 6, 2020. It is now read-only.

Commit 2c862af

Browse files
committed
get rid of populatable and bytesconvertable traits
1 parent a34bd38 commit 2c862af

File tree

17 files changed

+54
-203
lines changed

17 files changed

+54
-203
lines changed

ethcore/src/builtin.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,14 @@ impl Impl for EcRecover {
127127
let s = H256::from_slice(&input[96..128]);
128128

129129
let bit = match v[31] {
130-
27 | 28 if &v.as_slice()[..31] == &[0; 31] => v[31] - 27,
130+
27 | 28 if &v.0[..31] == &[0; 31] => v[31] - 27,
131131
_ => return,
132132
};
133133

134134
let s = Signature::from_rsv(&r, &s, bit);
135135
if s.is_valid() {
136136
if let Ok(p) = ec_recover(&s, &hash) {
137-
let r = p.as_slice().sha3();
137+
let r = p.sha3();
138138

139139
let out_len = min(output.len(), 32);
140140

ethcore/src/error.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use ethkey::Error as EthkeyError;
2828

2929
pub use types::executed::{ExecutionError, CallError};
3030

31-
#[derive(Debug, PartialEq, Clone)]
31+
#[derive(Debug, PartialEq, Clone, Copy)]
3232
/// Errors concerning transaction processing.
3333
pub enum TransactionError {
3434
/// Transaction is already imported to the queue
@@ -87,7 +87,7 @@ impl fmt::Display for TransactionError {
8787
}
8888
}
8989

90-
#[derive(Debug, PartialEq, Eq)]
90+
#[derive(Debug, PartialEq, Clone, Copy, Eq)]
9191
/// Errors concerning block processing.
9292
pub enum BlockError {
9393
/// Block has too many uncles.
@@ -185,7 +185,7 @@ impl fmt::Display for BlockError {
185185
}
186186
}
187187

188-
#[derive(Debug, PartialEq)]
188+
#[derive(Debug, Clone, Copy, PartialEq)]
189189
/// Import to the block queue result
190190
pub enum ImportError {
191191
/// Already in the block chain.

ethcore/src/evm/interpreter/gasometer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ impl<Gas: CostType> Gasometer<Gas> {
7676
instructions::SSTORE => {
7777
let address = H256::from(stack.peek(0));
7878
let newval = stack.peek(1);
79-
let val = U256::from(ext.storage_at(&address).as_slice());
79+
let val = U256::from(&*ext.storage_at(&address));
8080

8181
let gas = if val.is_zero() && !newval.is_zero() {
8282
schedule.sstore_set_gas

ethcore/src/evm/interpreter/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -403,18 +403,18 @@ impl<Cost: CostType> Interpreter<Cost> {
403403
let offset = stack.pop_back();
404404
let size = stack.pop_back();
405405
let sha3 = self.mem.read_slice(offset, size).sha3();
406-
stack.push(U256::from(sha3.as_slice()));
406+
stack.push(U256::from(&*sha3));
407407
},
408408
instructions::SLOAD => {
409409
let key = H256::from(&stack.pop_back());
410-
let word = U256::from(ext.storage_at(&key).as_slice());
410+
let word = U256::from(&*ext.storage_at(&key));
411411
stack.push(word);
412412
},
413413
instructions::SSTORE => {
414414
let address = H256::from(&stack.pop_back());
415415
let val = stack.pop_back();
416416

417-
let current_val = U256::from(ext.storage_at(&address).as_slice());
417+
let current_val = U256::from(&*ext.storage_at(&address));
418418
// Increase refund for clear
419419
if !self.is_zero(&current_val) && self.is_zero(&val) {
420420
ext.inc_sstore_clears();
@@ -491,7 +491,7 @@ impl<Cost: CostType> Interpreter<Cost> {
491491
instructions::BLOCKHASH => {
492492
let block_number = stack.pop_back();
493493
let block_hash = ext.blockhash(&block_number);
494-
stack.push(U256::from(block_hash.as_slice()));
494+
stack.push(U256::from(&*block_hash));
495495
},
496496
instructions::COINBASE => {
497497
stack.push(address_to_u256(ext.env_info().author.clone()));
@@ -807,7 +807,7 @@ fn u256_to_address(value: &U256) -> Address {
807807

808808
#[inline]
809809
fn address_to_u256(value: Address) -> U256 {
810-
U256::from(H256::from(value).as_slice())
810+
U256::from(&*H256::from(value))
811811
}
812812

813813
#[test]

ethcore/src/pod_account.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl PodAccount {
5757
let mut stream = RlpStream::new_list(4);
5858
stream.append(&self.nonce);
5959
stream.append(&self.balance);
60-
stream.append(&sec_trie_root(self.storage.iter().map(|(k, v)| (k.to_vec(), encode(&U256::from(v.as_slice())).to_vec())).collect()));
60+
stream.append(&sec_trie_root(self.storage.iter().map(|(k, v)| (k.to_vec(), encode(&U256::from(&**v)).to_vec())).collect()));
6161
stream.append(&self.code.as_ref().unwrap_or(&vec![]).sha3());
6262
stream.out()
6363
}
@@ -71,7 +71,7 @@ impl PodAccount {
7171
let mut r = H256::new();
7272
let mut t = SecTrieDBMut::new(db, &mut r);
7373
for (k, v) in &self.storage {
74-
if let Err(e) = t.insert(k, &encode(&U256::from(v.as_slice()))) {
74+
if let Err(e) = t.insert(k, &encode(&U256::from(&**v))) {
7575
warn!("Encountered potential DB corruption: {}", e);
7676
}
7777
}

ethcore/src/spec/spec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ impl Spec {
235235
{
236236
let mut t = SecTrieDBMut::new(db, &mut root);
237237
for (address, account) in self.genesis_state.get().iter() {
238-
try!(t.insert(address.as_slice(), &account.rlp()));
238+
try!(t.insert(&**address, &account.rlp()));
239239
}
240240
}
241241
for (address, account) in self.genesis_state.get().iter() {

ethcore/src/state/account.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ impl Account {
287287
// so we can call overloaded `to_bytes` method
288288
let res = match v.is_zero() {
289289
true => t.remove(k),
290-
false => t.insert(k, &encode(&U256::from(v.as_slice()))),
290+
false => t.insert(k, &encode(&U256::from(&*v))),
291291
};
292292

293293
if let Err(e) = res {

ethcore/src/types/account_diff.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,10 @@ impl AccountDiff {
9898

9999
// TODO: refactor into something nicer.
100100
fn interpreted_hash(u: &H256) -> String {
101-
use util::bytes::*;
102-
103101
if u <= &H256::from(0xffffffff) {
104-
format!("{} = 0x{:x}", U256::from(u.as_slice()).low_u32(), U256::from(u.as_slice()).low_u32())
102+
format!("{} = 0x{:x}", U256::from(&**u).low_u32(), U256::from(&**u).low_u32())
105103
} else if u <= &H256::from(u64::max_value()) {
106-
format!("{} = 0x{:x}", U256::from(u.as_slice()).low_u64(), U256::from(u.as_slice()).low_u64())
104+
format!("{} = 0x{:x}", U256::from(&**u).low_u64(), U256::from(&**u).low_u64())
107105
// } else if u <= &H256::from("0xffffffffffffffffffffffffffffffffffffffff") {
108106
// format!("@{}", Address::from(u))
109107
} else {
@@ -113,7 +111,7 @@ fn interpreted_hash(u: &H256) -> String {
113111

114112
impl fmt::Display for AccountDiff {
115113
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
116-
use util::bytes::*;
114+
use util::bytes::ToPretty;
117115

118116
match self.nonce {
119117
Diff::Born(ref x) => try!(write!(f, " non {}", x)),

ethcore/src/types/transaction_import.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@
1818
1919
use ipc::binary::{BinaryConvertError, BinaryConvertable};
2020
use error::{TransactionError, Error};
21-
use util::Populatable;
2221

23-
#[derive(Debug, Clone, PartialEq)]
22+
#[derive(Debug, Clone, Copy, PartialEq)]
2423
/// Represents the result of importing transaction.
2524
pub enum TransactionImportResult {
2625
/// Transaction was imported to current queue.

ipc/rpc/src/binary.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
//! Binary representation of types
1818
19-
use util::bytes::Populatable;
2019
use util::{U256, U512, H256, H2048, Address};
2120
use std::mem;
2221
use std::collections::{VecDeque, BTreeMap};
@@ -706,14 +705,21 @@ pub fn serialize<T: BinaryConvertable>(t: &T) -> Result<Vec<u8>, BinaryError> {
706705
#[macro_export]
707706
macro_rules! binary_fixed_size {
708707
($target_ty: ty) => {
709-
impl BinaryConvertable for $target_ty {
708+
impl BinaryConvertable for $target_ty where $target_ty: Copy {
710709
fn from_bytes(bytes: &[u8], _length_stack: &mut ::std::collections::VecDeque<usize>) -> Result<Self, BinaryConvertError> {
711-
match bytes.len().cmp(&::std::mem::size_of::<$target_ty>()) {
710+
let size = ::std::mem::size_of::<$target_ty>();
711+
match bytes.len().cmp(&size) {
712712
::std::cmp::Ordering::Equal => (),
713-
_ => return Err(BinaryConvertError::size(::std::mem::size_of::<$target_ty>(), bytes.len())),
713+
_ => return Err(BinaryConvertError::size(size, bytes.len())),
714714
};
715-
let mut res: Self = unsafe { ::std::mem::uninitialized() };
716-
res.copy_raw(bytes);
715+
let res: Self = unsafe {
716+
let mut temp = ::std::mem::zeroed();
717+
let temp_ptr = &mut temp as *mut _ as *mut u8;
718+
::std::ptr::copy_nonoverlapping(bytes.as_ptr(), temp_ptr, size);
719+
720+
temp
721+
};
722+
717723
Ok(res)
718724
}
719725

@@ -731,14 +737,14 @@ macro_rules! binary_fixed_size {
731737
}
732738

733739
/// Fixed-sized version of Handshake struct
734-
#[derive(Clone, Debug, PartialEq, Eq)]
740+
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
735741
pub struct BinHandshake {
736742
api_version: BinVersion,
737743
protocol_version: BinVersion,
738744
}
739745

740746
/// Shorten version of semver Version without `pre` and `build` information
741-
#[derive(Clone, Debug, PartialEq, Eq)]
747+
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
742748
pub struct BinVersion {
743749
pub major: u64,
744750
pub minor: u64,

0 commit comments

Comments
 (0)