summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSanto Cariotti <santo@dcariotti.me>2025-06-17 09:12:08 +0000
committerSanto Cariotti <santo@dcariotti.me>2025-06-17 09:12:08 +0000
commit5607dc8d0df77ca64b5fa52cab026296279122a7 (patch)
treed1b5f1e88efa42a3a390bbe0780481e1a3e8b4f0 /src
parentd86751aa67c30fd0bea324a88964d4e151f9f288 (diff)
Avoid clone for pair also on proof
Diffstat (limited to 'src')
-rw-r--r--src/proof.rs18
1 files changed, 13 insertions, 5 deletions
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::<u8>::with_capacity(left_hash.len() + right_hash.len());
+ buffer.extend_from_slice(left_hash);
+ buffer.extend_from_slice(right_hash);
- let mut buffer = Vec::<u8>::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;