Reverse Vec and use pop() instead of remove(0) for effiency.

This commit is contained in:
Romain Ruetschi
2016-11-10 14:42:45 +01:00
parent 60d3158619
commit a30b4ac75c

View File

@ -93,16 +93,18 @@ impl <D, T> MerkleTree<D, T> where D: Digest, T: Hashable {
cur.push(leaf);
}
cur.reverse();
while cur.len() > 1 {
let mut next = Vec::with_capacity(len);
while cur.len() > 0 {
if cur.len() == 1 {
next.push(cur.remove(0));
next.push(cur.pop().unwrap());
}
else {
let left = cur.remove(0);
let right = cur.remove(0);
let right = cur.pop().unwrap();
let left = cur.pop().unwrap();
let combined_hash = combine_hashes::<D>(
&mut digest,