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.
This commit is contained in:
Martin Habovstiak 2022-07-28 23:02:06 +02:00
parent 57fff47408
commit 1003ca08e1
1 changed files with 1 additions and 3 deletions

View File

@ -364,9 +364,7 @@ impl<'a> GCSFilterWriter<'a> {
mapped.sort_unstable(); mapped.sort_unstable();
// write number of elements as varint // write number of elements as varint
let mut encoder = Vec::new(); let mut wrote = VarInt(mapped.len() as u64).consensus_encode(&mut self.writer)?;
VarInt(mapped.len() as u64).consensus_encode(&mut encoder).expect("in-memory writers don't error");
let mut wrote = self.writer.write(encoder.as_slice())?;
// write out deltas of sorted values into a Golonb-Rice coded bit stream // write out deltas of sorted values into a Golonb-Rice coded bit stream
let mut writer = BitStreamWriter::new(self.writer); let mut writer = BitStreamWriter::new(self.writer);