Skip to content

Commit 2af95d3

Browse files
authored
Avoid intermediate Vec in TreeKemPublic::update_hashes (#230)
[slice, slice].concat() creates an intermediate Vec, which can be avoided by chaining updated_leaves and trailing_blanks before the first Vec is created.
1 parent d160ba6 commit 2af95d3

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

mls-rs/src/tree_kem/tree_hash.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,22 +95,23 @@ impl TreeKemPublic {
9595
) -> Result<(), MlsError> {
9696
let num_leaves = self.total_leaf_count();
9797

98-
let trailing_blanks = (0..num_leaves)
99-
.rev()
100-
.map_while(|l| {
98+
let leaves = updated_leaves
99+
.iter()
100+
.copied()
101+
.chain((0..num_leaves).rev().map_while(|l| {
101102
self.tree_hashes
102103
.current
103104
.get(2 * l as usize)
104105
.is_none()
105106
.then_some(LeafIndex(l))
106-
})
107+
}))
107108
.collect::<Vec<_>>();
108109

109110
// Update the current hashes for direct paths of all modified leaves.
110111
tree_hash(
111112
&mut self.tree_hashes.current,
112113
&self.nodes,
113-
Some([updated_leaves, &trailing_blanks].concat()),
114+
Some(leaves),
114115
&[],
115116
num_leaves,
116117
cipher_suite_provider,

0 commit comments

Comments
 (0)