parent
92fd00f41e
commit
7200cfcbc9
@ -60,7 +60,7 @@ impl WriteCache {
|
||||
self.entries.insert(key, WriteCacheEntry::Remove);
|
||||
}
|
||||
|
||||
fn get(&self, key: &Vec<u8>) -> Option<Vec<u8>> {
|
||||
fn get(&self, key: &[u8]) -> Option<Vec<u8>> {
|
||||
self.entries.get(key).and_then(
|
||||
|vec_ref| match vec_ref {
|
||||
&WriteCacheEntry::Write(ref val) => Some(val.clone()),
|
||||
|
@ -16,8 +16,6 @@
|
||||
|
||||
//! Blockchain block.
|
||||
|
||||
#![cfg_attr(feature="dev", allow(ptr_arg))] // Because of &LastHashes -> &Vec<_>
|
||||
|
||||
use common::*;
|
||||
use engine::*;
|
||||
use state::*;
|
||||
@ -76,11 +74,11 @@ pub struct BlockRefMut<'a> {
|
||||
/// Block header.
|
||||
pub header: &'a mut Header,
|
||||
/// Block transactions.
|
||||
pub transactions: &'a Vec<SignedTransaction>,
|
||||
pub transactions: &'a [SignedTransaction],
|
||||
/// Block uncles.
|
||||
pub uncles: &'a Vec<Header>,
|
||||
pub uncles: &'a [Header],
|
||||
/// Transaction receipts.
|
||||
pub receipts: &'a Vec<Receipt>,
|
||||
pub receipts: &'a [Receipt],
|
||||
/// State.
|
||||
pub state: &'a mut State,
|
||||
/// Traces.
|
||||
@ -92,11 +90,11 @@ pub struct BlockRef<'a> {
|
||||
/// Block header.
|
||||
pub header: &'a Header,
|
||||
/// Block transactions.
|
||||
pub transactions: &'a Vec<SignedTransaction>,
|
||||
pub transactions: &'a [SignedTransaction],
|
||||
/// Block uncles.
|
||||
pub uncles: &'a Vec<Header>,
|
||||
pub uncles: &'a [Header],
|
||||
/// Transaction receipts.
|
||||
pub receipts: &'a Vec<Receipt>,
|
||||
pub receipts: &'a [Receipt],
|
||||
/// State.
|
||||
pub state: &'a State,
|
||||
/// Traces.
|
||||
@ -152,16 +150,16 @@ pub trait IsBlock {
|
||||
fn state(&self) -> &State { &self.block().state }
|
||||
|
||||
/// Get all information on transactions in this block.
|
||||
fn transactions(&self) -> &Vec<SignedTransaction> { &self.block().base.transactions }
|
||||
fn transactions(&self) -> &[SignedTransaction] { &self.block().base.transactions }
|
||||
|
||||
/// Get all information on receipts in this block.
|
||||
fn receipts(&self) -> &Vec<Receipt> { &self.block().receipts }
|
||||
fn receipts(&self) -> &[Receipt] { &self.block().receipts }
|
||||
|
||||
/// Get all information concerning transaction tracing in this block.
|
||||
fn traces(&self) -> &Option<Vec<Trace>> { &self.block().traces }
|
||||
|
||||
/// Get all uncles in this block.
|
||||
fn uncles(&self) -> &Vec<Header> { &self.block().base.uncles }
|
||||
fn uncles(&self) -> &[Header] { &self.block().base.uncles }
|
||||
}
|
||||
|
||||
/// Trait for a object that has a state database.
|
||||
|
@ -426,7 +426,7 @@ impl Client {
|
||||
};
|
||||
|
||||
// Commit results
|
||||
let receipts = block.receipts().clone();
|
||||
let receipts = block.receipts().to_owned();
|
||||
let traces = From::from(block.traces().clone().unwrap_or_else(Vec::new));
|
||||
|
||||
// CHECK! I *think* this is fine, even if the state_root is equal to another
|
||||
|
@ -143,7 +143,7 @@ impl Header {
|
||||
/// Get the difficulty field of the header.
|
||||
pub fn difficulty(&self) -> &U256 { &self.difficulty }
|
||||
/// Get the seal field of the header.
|
||||
pub fn seal(&self) -> &Vec<Bytes> { &self.seal }
|
||||
pub fn seal(&self) -> &[Bytes] { &self.seal }
|
||||
|
||||
// TODO: seal_at, set_seal_at &c.
|
||||
|
||||
|
@ -665,7 +665,7 @@ impl MinerService for Miner {
|
||||
};
|
||||
match (&self.options.pending_set, sealing_set) {
|
||||
(&PendingSet::AlwaysQueue, _) | (&PendingSet::SealingOrElseQueue, None) => queue.top_transactions(),
|
||||
(_, sealing) => sealing.map_or_else(Vec::new, |s| s.transactions().clone()),
|
||||
(_, sealing) => sealing.map_or_else(Vec::new, |s| s.transactions().to_owned()),
|
||||
}
|
||||
}
|
||||
|
||||
@ -702,7 +702,7 @@ impl MinerService for Miner {
|
||||
.iter()
|
||||
.map(|t| t.hash());
|
||||
|
||||
let receipts = pending.receipts().clone().into_iter();
|
||||
let receipts = pending.receipts().iter().cloned();
|
||||
|
||||
hashes.zip(receipts).collect()
|
||||
},
|
||||
|
@ -143,7 +143,7 @@ impl Spec {
|
||||
}
|
||||
|
||||
/// Get the known knodes of the network in enode format.
|
||||
pub fn nodes(&self) -> &Vec<String> { &self.nodes }
|
||||
pub fn nodes(&self) -> &[String] { &self.nodes }
|
||||
|
||||
/// Get the configured Network ID.
|
||||
pub fn network_id(&self) -> U256 { self.params.network_id }
|
||||
|
@ -40,9 +40,9 @@ impl Into<Vec<u8>> for Bytes {
|
||||
}
|
||||
|
||||
impl Deref for Bytes {
|
||||
type Target = Vec<u8>;
|
||||
type Target = [u8];
|
||||
|
||||
fn deref(&self) -> &Vec<u8> {
|
||||
fn deref(&self) -> &[u8] {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
@ -238,7 +238,7 @@ impl Configuration {
|
||||
})
|
||||
}).collect(),
|
||||
Some(_) => Vec::new(),
|
||||
None => spec.nodes().clone(),
|
||||
None => spec.nodes().to_owned(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -508,7 +508,7 @@ impl<C, S, M, EM> Eth for EthClient<C, S, M, EM> where
|
||||
fn compilers(&self, params: Params) -> Result<Value, Error> {
|
||||
try!(self.active());
|
||||
match params {
|
||||
Params::None => to_value(&vec![] as &Vec<String>),
|
||||
Params::None => to_value(&(&[] as &[String])),
|
||||
_ => Err(Error::invalid_params())
|
||||
}
|
||||
}
|
||||
|
@ -25,11 +25,11 @@ use std::str::FromStr;
|
||||
use jsonrpc_core::IoHandler;
|
||||
use util::H256;
|
||||
|
||||
fn origin_is_allowed(self_origin: &str, header: Option<&Vec<u8>>) -> bool {
|
||||
fn origin_is_allowed(self_origin: &str, header: Option<&[u8]>) -> bool {
|
||||
match header {
|
||||
None => false,
|
||||
Some(h) => {
|
||||
let v = String::from_utf8(h.clone()).ok();
|
||||
let v = String::from_utf8(h.to_owned()).ok();
|
||||
match v {
|
||||
Some(ref origin) if origin.starts_with("chrome-extension://") => true,
|
||||
Some(ref origin) if origin.starts_with(self_origin) => true,
|
||||
@ -84,8 +84,8 @@ pub struct Session {
|
||||
|
||||
impl ws::Handler for Session {
|
||||
fn on_request(&mut self, req: &ws::Request) -> ws::Result<(ws::Response)> {
|
||||
let origin = req.header("origin").or_else(|| req.header("Origin"));
|
||||
let host = req.header("host").or_else(|| req.header("Host"));
|
||||
let origin = req.header("origin").or_else(|| req.header("Origin")).map(|x| &x[..]);
|
||||
let host = req.header("host").or_else(|| req.header("Host")).map(|x| &x[..]);
|
||||
|
||||
// Check request origin and host header.
|
||||
if !origin_is_allowed(&self.self_origin, origin) && !(origin.is_none() && origin_is_allowed(&self.self_origin, host)) {
|
||||
|
@ -242,7 +242,7 @@ pub enum FromBytesError {
|
||||
}
|
||||
|
||||
/// Value that can be serialized from bytes array
|
||||
pub trait FromRawBytes : Sized {
|
||||
pub trait FromRawBytes: Sized {
|
||||
/// function that will instantiate and initialize object from slice
|
||||
fn from_bytes(d: &[u8]) -> Result<Self, FromBytesError>;
|
||||
}
|
||||
@ -255,7 +255,7 @@ impl<T> FromRawBytes for T where T: FixedHash {
|
||||
Ordering::Equal => ()
|
||||
};
|
||||
|
||||
let mut res: Self = unsafe { mem::uninitialized() };
|
||||
let mut res = T::zero();
|
||||
res.copy_raw(bytes);
|
||||
Ok(res)
|
||||
}
|
||||
@ -271,7 +271,7 @@ macro_rules! sized_binary_map {
|
||||
::std::cmp::Ordering::Greater => return Err(FromBytesError::TooLong),
|
||||
::std::cmp::Ordering::Equal => ()
|
||||
};
|
||||
let mut res: Self = unsafe { ::std::mem::uninitialized() };
|
||||
let mut res: Self = 0;
|
||||
res.copy_raw(bytes);
|
||||
Ok(res)
|
||||
}
|
||||
@ -298,7 +298,7 @@ sized_binary_map!(u32);
|
||||
sized_binary_map!(u64);
|
||||
|
||||
/// Value that can be serialized from variable-length byte array
|
||||
pub trait FromRawBytesVariable : Sized {
|
||||
pub trait FromRawBytesVariable: Sized {
|
||||
/// Create value from slice
|
||||
fn from_bytes_variable(bytes: &[u8]) -> Result<Self, FromBytesError>;
|
||||
}
|
||||
@ -326,7 +326,7 @@ impl<T> FromRawBytesVariable for Vec<T> where T: FromRawBytes {
|
||||
let size_of_t = mem::size_of::<T>();
|
||||
let length_in_chunks = bytes.len() / size_of_t;
|
||||
|
||||
let mut result = Vec::with_capacity(length_in_chunks );
|
||||
let mut result = Vec::with_capacity(length_in_chunks);
|
||||
unsafe { result.set_len(length_in_chunks) };
|
||||
for i in 0..length_in_chunks {
|
||||
*result.get_mut(i).unwrap() = try!(T::from_bytes(
|
||||
@ -339,7 +339,7 @@ impl<T> FromRawBytesVariable for Vec<T> where T: FromRawBytes {
|
||||
impl<V1, T2> FromRawBytes for (V1, T2) where V1: FromRawBytesVariable, T2: FromRawBytes {
|
||||
fn from_bytes(bytes: &[u8]) -> Result<Self, FromBytesError> {
|
||||
let header = 8usize;
|
||||
let mut map: (u64, ) = unsafe { mem::uninitialized() };
|
||||
let mut map: (u64, ) = (0,);
|
||||
|
||||
if bytes.len() < header { return Err(FromBytesError::NotLongEnough); }
|
||||
map.copy_raw(&bytes[0..header]);
|
||||
@ -358,7 +358,7 @@ impl<V1, V2, T3> FromRawBytes for (V1, V2, T3)
|
||||
{
|
||||
fn from_bytes(bytes: &[u8]) -> Result<Self, FromBytesError> {
|
||||
let header = 16usize;
|
||||
let mut map: (u64, u64, ) = unsafe { mem::uninitialized() };
|
||||
let mut map: (u64, u64, ) = (0, 0,);
|
||||
|
||||
if bytes.len() < header { return Err(FromBytesError::NotLongEnough); }
|
||||
map.copy_raw(&bytes[0..header]);
|
||||
@ -373,7 +373,7 @@ impl<V1, V2, T3> FromRawBytes for (V1, V2, T3)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, V1, T2> ToBytesWithMap for (&'a Vec<V1>, &'a T2) where V1: ToBytesWithMap, T2: ToBytesWithMap {
|
||||
impl<'a, V1, X1, T2> ToBytesWithMap for (X1, &'a T2) where V1: ToBytesWithMap, X1: Deref<Target=[V1]>, T2: ToBytesWithMap {
|
||||
fn to_bytes_map(&self) -> Vec<u8> {
|
||||
let header = 8usize;
|
||||
let v1_size = mem::size_of::<V1>();
|
||||
@ -390,9 +390,9 @@ impl<'a, V1, T2> ToBytesWithMap for (&'a Vec<V1>, &'a T2) where V1: ToBytesWithM
|
||||
|
||||
}
|
||||
|
||||
impl<'a, V1, V2, T3> ToBytesWithMap for (&'a Vec<V1>, &'a Vec<V2>, &'a T3)
|
||||
where V1: ToBytesWithMap,
|
||||
V2: ToBytesWithMap,
|
||||
impl<'a, V1, X1, V2, X2, T3> ToBytesWithMap for (X1, X2, &'a T3)
|
||||
where V1: ToBytesWithMap, X1: Deref<Target=[V1]>,
|
||||
V2: ToBytesWithMap, X2: Deref<Target=[V2]>,
|
||||
T3: ToBytesWithMap
|
||||
{
|
||||
fn to_bytes_map(&self) -> Vec<u8> {
|
||||
@ -433,7 +433,7 @@ pub trait ToBytesWithMap {
|
||||
|
||||
impl<T> ToBytesWithMap for T where T: FixedHash {
|
||||
fn to_bytes_map(&self) -> Vec<u8> {
|
||||
self.as_slice().to_vec()
|
||||
self.as_slice().to_owned()
|
||||
}
|
||||
}
|
||||
|
||||
@ -493,7 +493,7 @@ fn populate_big_types() {
|
||||
fn raw_bytes_from_tuple() {
|
||||
type Tup = (Vec<u16>, u16);
|
||||
|
||||
let tup = (vec![1u16, 1u16, 1u16, 1u16], 10u16);
|
||||
let tup: (&[u16], u16) = (&[1; 4], 10);
|
||||
let bytes = vec![
|
||||
// map
|
||||
8u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8,
|
||||
@ -505,18 +505,19 @@ fn raw_bytes_from_tuple() {
|
||||
// 10u16
|
||||
10u8, 0u8];
|
||||
|
||||
let tup_from = Tup::from_bytes(&bytes).unwrap();
|
||||
assert_eq!(tup, tup_from);
|
||||
let (v, x) = Tup::from_bytes(&bytes).unwrap();
|
||||
assert_eq!(tup, (&v[..], x));
|
||||
let tup_from = (v, x);
|
||||
|
||||
let tup_to = (&tup_from.0, &tup_from.1);
|
||||
let tup_to = (tup_from.0, &tup_from.1);
|
||||
let bytes_to = tup_to.to_bytes_map();
|
||||
assert_eq!(bytes_to, bytes);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bytes_map_from_triple() {
|
||||
let data = (vec![2u16; 6], vec![6u32; 3], 12u64);
|
||||
let bytes_map = (&data.0, &data.1, &data.2).to_bytes_map();
|
||||
let data: (&[u16], &[u32], u64) = (&[2; 6], &[6; 3], 12u64);
|
||||
let bytes_map = (data.0, data.1, &data.2).to_bytes_map();
|
||||
assert_eq!(bytes_map, vec![
|
||||
// data map 2 x u64
|
||||
12, 0, 0, 0, 0, 0, 0, 0,
|
||||
|
@ -195,7 +195,7 @@ fn hash256rlp(input: &[(Vec<u8>, Vec<u8>)], pre_len: usize, stream: &mut RlpStre
|
||||
}
|
||||
|
||||
// take slices
|
||||
let key: &Vec<u8> = &input[0].0;
|
||||
let key: &[u8] = &input[0].0;
|
||||
let value: &[u8] = &input[0].1;
|
||||
|
||||
// if the slice contains just one item, append the suffix of the key
|
||||
|
@ -17,23 +17,23 @@
|
||||
//! Vector extensions.
|
||||
|
||||
/// Returns len of prefix shared with elem
|
||||
///
|
||||
///
|
||||
/// ```rust
|
||||
/// extern crate ethcore_util as util;
|
||||
/// use util::vector::SharedPrefix;
|
||||
///
|
||||
///
|
||||
/// fn main () {
|
||||
/// let a = vec![1,2,3,3,5];
|
||||
/// let b = vec![1,2,3];
|
||||
/// assert_eq!(a.shared_prefix_len(&b), 3);
|
||||
/// }
|
||||
/// ```
|
||||
pub trait SharedPrefix <T> {
|
||||
pub trait SharedPrefix<T> {
|
||||
/// Get common prefix length
|
||||
fn shared_prefix_len(&self, elem: &[T]) -> usize;
|
||||
}
|
||||
|
||||
impl <T> SharedPrefix<T> for Vec<T> where T: Eq {
|
||||
impl<T> SharedPrefix<T> for [T] where T: Eq {
|
||||
fn shared_prefix_len(&self, elem: &[T]) -> usize {
|
||||
use std::cmp;
|
||||
let len = cmp::min(self.len(), elem.len());
|
||||
@ -58,7 +58,7 @@ mod test {
|
||||
let b = vec![1,2,3];
|
||||
assert_eq!(a.shared_prefix_len(&b), 3);
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_shared_prefix3() {
|
||||
let a = vec![1,2,3,4,5,6];
|
||||
|
Loading…
Reference in New Issue
Block a user