Commit dc945f08 authored by David's avatar David

Replace ElasticArray with SmallVec

The elastic-array crate is a fine piece of software but it'd be good to prefer crates that are commonly used in the ecosystem and likely to be well maintained. smallvec is at v1.0 and generally well-regarded.

Related PRs:

	- [parity-common #282](https://github.com/paritytech/parity-common/pull/282)
	– [trie-db #46](https://github.com/paritytech/trie/pull/46)
parent 43eb2eab
Pipeline #71763 failed with stages
in 23 seconds
This diff is collapsed.
......@@ -136,6 +136,7 @@ members = [
"parity-clib",
]
# todo[dvdplm]: remove before merge
[patch.crates-io]
kvdb = { path = "../parity-common/kvdb" }
kvdb-memorydb = { path = "../parity-common/kvdb-memorydb" }
......@@ -147,3 +148,5 @@ rlp = { path = "../parity-common/rlp" }
ethbloom = { path = "../parity-common/ethbloom" }
triehash = { path = "../parity-common/triehash" }
fixed-hash = { path = "../parity-common/fixed-hash" }
trie-db = { path = "../trie/trie-db" }
hash-db = { path = "../trie/hash-db" }
......@@ -155,9 +155,8 @@ fn check_first_proof(machine: &Machine, contract_address: Address, old_header: H
fn decode_first_proof(rlp: &Rlp) -> Result<(Header, Vec<DBValue>), EthcoreError> {
let header = rlp.val_at(0)?;
let state_items = rlp.at(1)?.iter().map(|x| {
let mut val = DBValue::new();
val.append_slice(x.data()?);
Ok(val)
// todo[dvdplm] can avoid copy with `from_buf()` here?
Ok(DBValue::from_slice(x.data()?))
}).collect::<Result<_, EthcoreError>>()?;
Ok((header, state_items))
......
......@@ -1507,9 +1507,8 @@ pub mod execution {
fn decode(rlp: &Rlp) -> Result<Self, DecoderError> {
let mut items = Vec::new();
for raw_item in rlp.iter() {
let mut item = DBValue::new();
item.append_slice(raw_item.data()?);
items.push(item);
// todo[dvdplm] can avoid copy with `from_buf()` here?
items.push(DBValue::from_slice(raw_item.data()?))
}
Ok(Response { items })
......@@ -1854,9 +1853,8 @@ mod tests {
let full_req = Request::Execution(req.clone());
let res = ExecutionResponse {
items: vec![DBValue::new(), {
let mut value = DBValue::new();
value.append_slice(&[1, 1, 1, 2, 3]);
value
// todo[dvdplm] can avoid copy with `from_buf()` here?
DBValue::from_slice(&[1, 1, 1, 2, 3])
}],
};
let full_res = Response::Execution(res.clone());
......
......@@ -8,11 +8,11 @@ license = "GPL-3.0"
[dependencies]
trie-db = "0.16.0"
keccak-hasher = { version = "0.1.1", path = "../keccak-hasher" }
hash-db = "0.15.0"
hash-db = "0.15.2"
rlp = "0.4.4"
parity-bytes = "0.1"
ethereum-types = "0.8.0"
elastic-array = "0.10"
smallvec = "1.0.0"
[dev-dependencies]
memory-db = "0.15.0"
......
......@@ -17,7 +17,7 @@
//! Façade crate for `patricia_trie` for Ethereum specific impls
pub extern crate trie_db as trie; // `pub` because we need to import this crate for the tests in `patricia_trie` and there were issues: https://gist.github.com/dvdplm/869251ee557a1b4bd53adc7c971979aa
extern crate elastic_array;
extern crate smallvec;
extern crate parity_bytes;
extern crate ethereum_types;
extern crate hash_db;
......@@ -59,7 +59,7 @@ impl trie_db::TrieLayout for Layout {
/// extern crate keccak_hasher;
/// extern crate memory_db;
/// extern crate ethereum_types;
/// extern crate elastic_array;
/// extern crate smallvec;
/// extern crate journaldb;
///
/// use trie::*;
......@@ -68,9 +68,8 @@ impl trie_db::TrieLayout for Layout {
/// use memory_db::*;
/// use ethereum_types::H256;
/// use ethtrie::{TrieDB, TrieDBMut};
/// use elastic_array::ElasticArray128;
///
/// type DBValue = ElasticArray128<u8>;
/// type DBValue = smallvec::SmallVec<[u8; 128]>;
///
/// fn main() {
/// let mut memdb = journaldb::new_memory_db();
......@@ -104,7 +103,7 @@ pub type FatDB<'db> = trie::FatDB<'db, Layout>;
/// extern crate keccak_hasher;
/// extern crate memory_db;
/// extern crate ethereum_types;
/// extern crate elastic_array;
/// extern crate smallvec;
/// extern crate journaldb;
///
/// use keccak_hash::KECCAK_NULL_RLP;
......@@ -112,10 +111,9 @@ pub type FatDB<'db> = trie::FatDB<'db, Layout>;
/// use keccak_hasher::KeccakHasher;
/// use memory_db::*;
/// use ethereum_types::H256;
/// use elastic_array::ElasticArray128;
/// use trie::Trie;
///
/// type DBValue = ElasticArray128<u8>;
/// type DBValue = smallvec::SmallVec<[u8; 128]>;
///
/// fn main() {
/// let mut memdb = journaldb::new_memory_db();
......@@ -166,9 +164,9 @@ mod tests {
let t = TrieDB::new(&memdb, &root).unwrap();
assert!(t.contains(b"foo").unwrap());
assert!(t.contains(b"fog").unwrap());
assert_eq!(t.get(b"foo").unwrap().unwrap(), b"bar".to_vec());
assert_eq!(t.get(b"fog").unwrap().unwrap(), b"b".to_vec());
assert_eq!(t.get(b"fot").unwrap().unwrap(), vec![0u8;33]);
assert_eq!(t.get(b"foo").unwrap().unwrap().to_vec(), b"bar".to_vec());
assert_eq!(t.get(b"fog").unwrap().unwrap().to_vec(), b"b".to_vec());
assert_eq!(t.get(b"fot").unwrap().unwrap().to_vec(), vec![0u8;33]);
}
#[test]
......@@ -183,8 +181,8 @@ mod tests {
let t = TrieDB::new(&memdb, &root).unwrap();
assert!(t.contains(b"foo").unwrap());
assert!(t.contains(b"fog").unwrap());
assert_eq!(t.get(b"foo").unwrap().unwrap(), b"b".to_vec());
assert_eq!(t.get(b"fog").unwrap().unwrap(), b"a".to_vec());
assert_eq!(t.get(b"foo").unwrap().unwrap().to_vec(), b"b".to_vec());
assert_eq!(t.get(b"fog").unwrap().unwrap().to_vec(), b"a".to_vec());
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment