Skip to content

Commit

Permalink
Merge #1146: Remove needless allocation from BIP-158 encoding
Browse files Browse the repository at this point in the history
1003ca0 Remove needless allocation from BIP-158 encoding (Martin Habovstiak)

Pull request description:

  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.

ACKs for top commit:
  tcharding:
    ACK 1003ca0
  sanket1729:
    ACK 1003ca0
  apoelstra:
    ACK 1003ca0

Tree-SHA512: 01e198726f45ef1b0e4bbe80154674d9db12350281e682531259d1d6467881bc7503cfed30d3837813437c3081a35ba7893c3ae4490d07daf20f1b75dbc62d52
  • Loading branch information
apoelstra committed Jul 29, 2022
2 parents ed3fb45 + 1003ca0 commit 0b02e43
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions src/util/bip158.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 0b02e43

Please sign in to comment.