Skip to content

Commit a33de6a

Browse files
committed
Remove needless allocation from BIP-158 encoding
The BIP-158 finalize code was serializing value to `Vec` only to serialize it to writer right away. Thus the intermediary `Vec` was not needed. Even more, the code used `write` which, while correct in case of `Vec`, could trigger code analysis tools or reviewers.
1 parent cf56672 commit a33de6a

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

src/util/bip158.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -364,9 +364,7 @@ impl<'a> GCSFilterWriter<'a> {
364364
mapped.sort_unstable();
365365

366366
// write number of elements as varint
367-
let mut encoder = Vec::new();
368-
VarInt(mapped.len() as u64).consensus_encode(&mut encoder).expect("in-memory writers don't error");
369-
let mut wrote = self.writer.write(encoder.as_slice())?;
367+
let mut wrote = VarInt(mapped.len() as u64).consensus_encode(&mut self.writer)?;
370368

371369
// write out deltas of sorted values into a Golonb-Rice coded bit stream
372370
let mut writer = BitStreamWriter::new(self.writer);

0 commit comments

Comments
 (0)