diff --git a/src/hash_builder/mod.rs b/src/hash_builder/mod.rs index a639492..82fdad5 100644 --- a/src/hash_builder/mod.rs +++ b/src/hash_builder/mod.rs @@ -322,7 +322,7 @@ impl HashBuilder { let state_mask = self.groups[len]; let hash_mask = self.hash_masks[len]; let branch_node = BranchNode::new(&self.stack); - let children = branch_node.children(state_mask, hash_mask).collect(); + let children = branch_node.children(state_mask, hash_mask); self.rlp_buf.clear(); let rlp = branch_node.rlp(state_mask, &mut self.rlp_buf); diff --git a/src/nodes/branch.rs b/src/nodes/branch.rs index dd818c5..8b13441 100644 --- a/src/nodes/branch.rs +++ b/src/nodes/branch.rs @@ -19,22 +19,18 @@ impl<'a> BranchNode<'a> { /// Given the hash and state mask of children present, return an iterator over the stack items /// that match the mask. - pub fn children( - &self, - state_mask: TrieMask, - hash_mask: TrieMask, - ) -> impl Iterator + '_ { + pub fn children(&self, state_mask: TrieMask, hash_mask: TrieMask) -> Vec { let mut index = self.stack.len() - state_mask.count_ones() as usize; - CHILD_INDEX_RANGE.filter_map(move |digit| { - let mut child = None; + let mut children = Vec::with_capacity(CHILD_INDEX_RANGE.len()); + for digit in CHILD_INDEX_RANGE { if state_mask.is_bit_set(digit) { if hash_mask.is_bit_set(digit) { - child = Some(&self.stack[index]); + children.push(B256::from_slice(&self.stack[index][1..])); } index += 1; } - child.map(|child| B256::from_slice(&child[1..])) - }) + } + children } /// Returns the RLP encoding of the branch node given the state mask of children present.