Skip to content

Commit bcff97d

Browse files
committed
parallelization
1 parent b9e4d74 commit bcff97d

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/dynamic_merkle_tree.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -491,11 +491,12 @@ pub trait DynamicTreeStorage<H: Hasher>:
491491
let start = index_from_leaf(num_leaves);
492492

493493
if start < len {
494-
for hash in self[start..].iter() {
494+
self[start..].par_iter().try_for_each(|hash| {
495495
if hash != empty_value {
496496
bail!("Storage contains non-empty values past the last leaf");
497497
}
498-
}
498+
Ok(())
499+
})?;
499500
}
500501

501502
for height in 0..=depth {
@@ -912,9 +913,12 @@ fn init_subtree<H: Hasher>(sparse_column: &[H::Hash], storage_slice: &mut [H::Ha
912913
fn init_subtree_with_leaves<H: Hasher>(storage: &mut [H::Hash], leaves: &[H::Hash]) -> H::Hash {
913914
let (depth, width) = subtree_depth_width(storage);
914915

915-
leaves.iter().enumerate().for_each(|(i, &val)| {
916-
storage[width + i] = val;
917-
});
916+
storage[width..(width + leaves.len())]
917+
.par_iter_mut()
918+
.zip(leaves.par_iter())
919+
.for_each(|(val, leaf)| {
920+
*val = *leaf;
921+
});
918922

919923
// Iterate over mutable layers of the tree
920924
for current_depth in (1..=depth).rev() {

0 commit comments

Comments
 (0)