Skip to content

Commit

Permalink
Use iterators instead of continue (#309)
Browse files Browse the repository at this point in the history
  • Loading branch information
richardpringle authored Oct 6, 2023
1 parent 655a791 commit 404a070
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions firewood/src/merkle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,6 @@ impl<S: ShaleStore<Node> + Send + Sync> Merkle<S> {
let mut parents = Vec::new();

let mut next_node = Some(self.get_node(root)?);
let mut nskip = 0;

// wrap the current value into an Option to indicate whether it has been
// inserted yet. If we haven't inserted it after we traverse the tree, we
Expand All @@ -378,12 +377,6 @@ impl<S: ShaleStore<Node> + Send + Sync> Merkle<S> {
break;
};

// special handling for extension nodes
if nskip > 0 {
nskip -= 1;
continue;
}

// move the current node into node; next_node becomes None
// unwrap() is okay here since we are certain we have something
// in next_node at this point
Expand Down Expand Up @@ -439,8 +432,8 @@ impl<S: ShaleStore<Node> + Send + Sync> Merkle<S> {
NodeType::Extension(n) => {
let n_path = n.path().to_vec();
let n_ptr = n.chd();
nskip = n_path.len() - 1;
let rem_path = once(key_nib).chain(key_nibbles.clone()).collect::<Vec<_>>();
let n_path_len = n_path.len();

if let Some(v) = self.split(
node,
Expand All @@ -451,6 +444,10 @@ impl<S: ShaleStore<Node> + Send + Sync> Merkle<S> {
val.take().unwrap(),
&mut deleted,
)? {
(0..n_path_len).skip(1).for_each(|_| {
key_nibbles.next();
});

// we couldn't split this, so we
// skip n_path items and follow the
// extension node's next pointer
Expand Down

0 comments on commit 404a070

Please sign in to comment.