From 5607dc8d0df77ca64b5fa52cab026296279122a7 Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Tue, 17 Jun 2025 11:12:08 +0200 Subject: Avoid clone for pair also on proof --- src/proof.rs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'src/proof.rs') diff --git a/src/proof.rs b/src/proof.rs index 4acfea6..14370f2 100644 --- a/src/proof.rs +++ b/src/proof.rs @@ -101,13 +101,21 @@ impl Proofer for DefaultProofer<'_> { // Move to the next level let mut next_level = Vec::new(); for pair in current_level.chunks(2) { - let (left, right) = (pair[0].clone(), pair[1].clone()); + let (left, right) = (&pair[0], &pair[1]); + + let (left_hash, right_hash) = (left.hash().as_bytes(), right.hash().as_bytes()); + + let mut buffer = Vec::::with_capacity(left_hash.len() + right_hash.len()); + buffer.extend_from_slice(left_hash); + buffer.extend_from_slice(right_hash); - let mut buffer = Vec::::new(); - buffer.extend_from_slice(left.hash().as_bytes()); - buffer.extend_from_slice(right.hash().as_bytes()); let hash = self.hasher.hash(&buffer); - next_level.push(Node::new_internal(&buffer, hash, left, right)); + next_level.push(Node::new_internal( + &buffer, + hash, + left.clone(), + right.clone(), + )); } current_level = next_level; current_index /= 2; -- cgit v1.2.3-71-g8e6c