less unsafe code

This commit is contained in:
debris 2017-08-21 10:19:53 +02:00
parent a247d5b2dc
commit b68375d462

View File

@ -292,19 +292,17 @@ impl<'a> TrieDBIterator<'a> {
/// The present key. /// The present key.
fn key(&self) -> Bytes { fn key(&self) -> Bytes {
// collapse the key_nibbles down to bytes. // collapse the key_nibbles down to bytes.
unsafe { let nibbles = &self.key_nibbles;
let size = self.key_nibbles.len() / 2; let mut i = 0;
let mut ptr = self.key_nibbles.as_ptr(); let mut result = Bytes::with_capacity(nibbles.len() / 2);
let mut result = Bytes::with_capacity(size); let len = nibbles.len() - 1;
while i < len {
for _ in 0..size { result.push(nibbles[i] * 16 + nibbles[i + 1]);
result.push(*ptr * 16 + *ptr.offset(1)); i += 2;
ptr = ptr.offset(2);
} }
result result
} }
} }
}
impl<'a> TrieIterator for TrieDBIterator<'a> { impl<'a> TrieIterator for TrieDBIterator<'a> {
/// Position the iterator on the first element with key >= `key` /// Position the iterator on the first element with key >= `key`