Less slices (#9176)

* Less slices

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
Squirrel
2021-06-23 13:33:48 +01:00
committed by GitHub
parent 7b50bbb9bf
commit 07449840bd
11 changed files with 41 additions and 46 deletions
+4 -4
View File
@@ -211,7 +211,7 @@ pub fn read_trie_value<L: TrieConfiguration, DB: hash_db::HashDBRef<L::Hash, tri
root: &TrieHash<L>,
key: &[u8]
) -> Result<Option<Vec<u8>>, Box<TrieError<L>>> {
Ok(TrieDB::<L>::new(&*db, root)?.get(key).map(|x| x.map(|val| val.to_vec()))?)
TrieDB::<L>::new(&*db, root)?.get(key).map(|x| x.map(|val| val.to_vec()))
}
/// Read a value from the trie with given Query.
@@ -225,7 +225,7 @@ pub fn read_trie_value_with<
key: &[u8],
query: Q
) -> Result<Option<Vec<u8>>, Box<TrieError<L>>> {
Ok(TrieDB::<L>::new(&*db, root)?.get_with(key, query).map(|x| x.map(|val| val.to_vec()))?)
TrieDB::<L>::new(&*db, root)?.get_with(key, query).map(|x| x.map(|val| val.to_vec()))
}
/// Determine the empty trie root.
@@ -317,7 +317,7 @@ pub fn read_child_trie_value<L: TrieConfiguration, DB>(
root.as_mut().copy_from_slice(root_slice);
let db = KeySpacedDB::new(&*db, keyspace);
Ok(TrieDB::<L>::new(&db, &root)?.get(key).map(|x| x.map(|val| val.to_vec()))?)
TrieDB::<L>::new(&db, &root)?.get(key).map(|x| x.map(|val| val.to_vec()))
}
/// Read a value from the child trie with given query.
@@ -336,7 +336,7 @@ pub fn read_child_trie_value_with<L: TrieConfiguration, Q: Query<L::Hash, Item=D
root.as_mut().copy_from_slice(root_slice);
let db = KeySpacedDB::new(&*db, keyspace);
Ok(TrieDB::<L>::new(&db, &root)?.get_with(key, query).map(|x| x.map(|val| val.to_vec()))?)
TrieDB::<L>::new(&db, &root)?.get_with(key, query).map(|x| x.map(|val| val.to_vec()))
}
/// `HashDB` implementation that append a encoded prefix (unique id bytes) in addition to the
+3 -3
View File
@@ -259,7 +259,7 @@ fn partial_encode(partial: Partial, node_kind: NodeKind) -> Vec<u8> {
if number_nibble_encoded > 0 {
output.push(nibble_ops::pad_right((partial.0).1));
}
output.extend_from_slice(&partial.1[..]);
output.extend_from_slice(partial.1);
output
}
@@ -272,8 +272,8 @@ const BITMAP_LENGTH: usize = 2;
pub(crate) struct Bitmap(u16);
impl Bitmap {
pub fn decode(data: &[u8]) -> Result<Self, Error> {
Ok(Bitmap(u16::decode(&mut &data[..])?))
pub fn decode(mut data: &[u8]) -> Result<Self, Error> {
Ok(Bitmap(u16::decode(&mut data)?))
}
pub fn value_at(&self, i: usize) -> bool {