Skip to content

Commit 24f97b7

Browse files
perf: preallocate omitted marker buffer
Reserve the final omitted-marker capacity before extending from the iterator to avoid incremental growth in selective disclosure construction. Co-Authored-By: OpenAI Codex <noreply@openai.com>
1 parent 7505abb commit 24f97b7

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

lightning/src/offers/merkle.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,10 @@ pub(super) fn compute_selective_disclosure<'a>(
389389
if tlv_data.is_empty() {
390390
return Err(SelectiveDisclosureError::EmptyTlvStream);
391391
}
392-
let omitted_markers: Vec<_> = compute_omitted_markers(tlv_data.iter()).collect();
392+
let num_omitted_markers =
393+
tlv_data.iter().filter(|data| !data.is_included && data.tlv_type != 0).count();
394+
let mut omitted_markers = Vec::with_capacity(num_omitted_markers);
395+
omitted_markers.extend(compute_omitted_markers(tlv_data.iter()));
393396
let (merkle_root, missing_hashes) = build_tree_with_disclosure(&tlv_data, &branch_tag);
394397

395398
Ok(SelectiveDisclosure { leaf_hashes, omitted_markers, missing_hashes, merkle_root })

0 commit comments

Comments
 (0)