From 1003ca08e16532bcba34de7774b65b0cf305d93b Mon Sep 17 00:00:00 2001 From: Martin Habovstiak Date: Thu, 28 Jul 2022 23:02:06 +0200 Subject: [PATCH] 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. --- src/util/bip158.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/util/bip158.rs b/src/util/bip158.rs index 0ae18091..3be893da 100644 --- a/src/util/bip158.rs +++ b/src/util/bip158.rs @@ -364,9 +364,7 @@ impl<'a> GCSFilterWriter<'a> { mapped.sort_unstable(); // write number of elements as varint - let mut encoder = Vec::new(); - 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())?; + let mut wrote = VarInt(mapped.len() as u64).consensus_encode(&mut self.writer)?; // write out deltas of sorted values into a Golonb-Rice coded bit stream let mut writer = BitStreamWriter::new(self.writer);