less unsafe code

This commit is contained in:
debris 2017-08-21 10:19:53 +02:00
parent a247d5b2dc
commit b68375d462
1 changed files with 8 additions and 10 deletions

View File

@ -292,17 +292,15 @@ 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
} }
} }