added benchmarks and few optimisations for rlp encoding

This commit is contained in:
debris
2015-11-26 15:43:52 +01:00
parent 4fcf044edd
commit 21a5d5418b
3 changed files with 44 additions and 9 deletions

View File

@@ -60,6 +60,7 @@ impl ToBytes for u64 {
fn to_bytes(&self) -> Vec<u8> {
let mut res= vec![];
let count = self.to_bytes_len();
res.reserve(count);
for i in 0..count {
let j = count - 1 - i;
res.push((*self >> (j * 8)) as u8);
@@ -89,6 +90,7 @@ macro_rules! impl_uint_to_bytes {
fn to_bytes(&self) -> Vec<u8> {
let mut res= vec![];
let count = self.to_bytes_len();
res.reserve(count);
for i in 0..count {
let j = count - 1 - i;
res.push(self.byte(j));

View File

@@ -233,7 +233,6 @@ macro_rules! construct_uint {
type Err = FromHexError;
fn from_str(value: &str) -> Result<$name, Self::Err> {
println!("{}", value);
let bytes: &[u8] = &try!(value.from_hex());
Ok(From::from(bytes))
}