Upgrade elastic-array to 0.9.0

This is a huge change, which includes some changes to replace code that
originally cloned to reuse allocations instead. The updated
`elastic-array` crate renames its consuming `Vec`-conversion method to
`into_vec`, which means that I can do a simple
`sed -i 's/to_vec/into_vec/'` and then fix the compilation errors.

This commit is probably a minor performance win and definitely a
significant readability win.
This commit is contained in:
Vurich
2017-06-28 14:16:53 +02:00
parent 826bf28196
commit 3d8dc11442
76 changed files with 212 additions and 211 deletions

View File

@@ -126,7 +126,7 @@ pub fn compute_root<I>(cht_num: u64, iterable: I) -> Option<H256>
let start_num = start_number(cht_num) as usize;
for (i, (h, td)) in iterable.into_iter().take(SIZE as usize).enumerate() {
v.push((key!(i + start_num).to_vec(), val!(h, td).to_vec()))
v.push((key!(i + start_num).into_vec(), val!(h, td).into_vec()))
}
if v.len() == SIZE as usize {

View File

@@ -388,7 +388,7 @@ impl HeaderChain {
None => {
match self.db.get(self.col, &hash) {
Ok(db_value) => {
db_value.map(|x| x.to_vec()).map(encoded::Header::new)
db_value.map(|x| x.into_vec()).map(encoded::Header::new)
.and_then(|header| {
cache.insert_block_header(hash.clone(), header.clone());
Some(header)

View File

@@ -137,7 +137,7 @@ impl Provider for TestProvider {
fn storage_proof(&self, req: request::CompleteStorageRequest) -> Option<request::StorageResponse> {
Some(StorageResponse {
proof: vec![::rlp::encode(&req.key_hash).to_vec()],
proof: vec![::rlp::encode(&req.key_hash).into_vec()],
value: req.key_hash | req.address_hash,
})
}

View File

@@ -738,7 +738,7 @@ impl BlockReceipts {
/// Check a response with receipts against the stored header.
pub fn check_response(&self, cache: &Mutex<::cache::Cache>, receipts: &[Receipt]) -> Result<Vec<Receipt>, Error> {
let receipts_root = self.0.as_ref()?.receipts_root();
let found_root = ::util::triehash::ordered_trie_root(receipts.iter().map(|r| ::rlp::encode(r).to_vec()));
let found_root = ::util::triehash::ordered_trie_root(receipts.iter().map(|r| ::rlp::encode(r).into_vec()));
match receipts_root == found_root {
true => {
@@ -900,9 +900,9 @@ mod tests {
fn check_header_by_hash() {
let mut header = Header::new();
header.set_number(10_000);
header.set_extra_data(b"test_header".to_vec());
header.set_extra_data(b"test_header".into_vec());
let hash = header.hash();
let raw_header = encoded::Header::new(::rlp::encode(&header).to_vec());
let raw_header = encoded::Header::new(::rlp::encode(&header).into_vec());
let cache = Mutex::new(make_cache());
assert!(HeaderByHash(hash.into()).check_response(&cache, &hash.into(), &[raw_header]).is_ok())
@@ -916,10 +916,10 @@ mod tests {
let mut body_stream = RlpStream::new_list(2);
body_stream.begin_list(0).begin_list(0);
let req = Body(encoded::Header::new(::rlp::encode(&header).to_vec()).into());
let req = Body(encoded::Header::new(::rlp::encode(&header).into_vec()).into());
let cache = Mutex::new(make_cache());
let response = encoded::Body::new(body_stream.drain().to_vec());
let response = encoded::Body::new(body_stream.drain().into_vec());
assert!(req.check_response(&cache, &response).is_ok())
}
@@ -934,12 +934,12 @@ mod tests {
let mut header = Header::new();
let receipts_root = ::util::triehash::ordered_trie_root(
receipts.iter().map(|x| ::rlp::encode(x).to_vec())
receipts.iter().map(|x| ::rlp::encode(x).into_vec())
);
header.set_receipts_root(receipts_root);
let req = BlockReceipts(encoded::Header::new(::rlp::encode(&header).to_vec()).into());
let req = BlockReceipts(encoded::Header::new(::rlp::encode(&header).into_vec()).into());
let cache = Mutex::new(make_cache());
assert!(req.check_response(&cache, &receipts).is_ok())
@@ -953,7 +953,7 @@ mod tests {
let mut db = MemoryDB::new();
let mut header = Header::new();
header.set_number(123_456);
header.set_extra_data(b"test_header".to_vec());
header.set_extra_data(b"test_header".into_vec());
let addr = Address::random();
let rand_acc = || {
@@ -987,7 +987,7 @@ mod tests {
header.set_state_root(root.clone());
let req = Account {
header: encoded::Header::new(::rlp::encode(&header).to_vec()).into(),
header: encoded::Header::new(::rlp::encode(&header).into_vec()).into(),
address: addr,
};
@@ -1001,7 +1001,7 @@ mod tests {
let code_hash = ::util::Hashable::sha3(&code);
let header = Header::new();
let req = Code {
header: encoded::Header::new(::rlp::encode(&header).to_vec()).into(),
header: encoded::Header::new(::rlp::encode(&header).into_vec()).into(),
code_hash: code_hash.into(),
};

View File

@@ -1673,7 +1673,7 @@ mod tests {
let full_req = Request::Headers(req.clone());
let res = HeadersResponse {
headers: vec![
::ethcore::encoded::Header::new(::rlp::encode(&Header::default()).to_vec())
::ethcore::encoded::Header::new(::rlp::encode(&Header::default()).into_vec())
]
};
let full_res = Response::Headers(res.clone());