Skip to content

Commit

Permalink
Use assert_eq for encoded data length check
Browse files Browse the repository at this point in the history
According to the Rust docs for `debug_assert` it should only be used if
there a proved performance costs to using `assert`.

Checking the length of a vector is fast, therefore its unlikely that
using `assert_eq` will have any noticeable performance costs.
  • Loading branch information
tcharding committed Apr 18, 2022
1 parent b4daa14 commit e2fff70
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/consensus/encode.rs
Expand Up @@ -140,7 +140,7 @@ impl From<psbt::Error> for Error {
pub fn serialize<T: Encodable + ?Sized>(data: &T) -> Vec<u8> {
let mut encoder = Vec::new();
let len = data.consensus_encode(&mut encoder).expect("in-memory writers don't error");
debug_assert_eq!(len, encoder.len());
assert_eq!(len, encoder.len());
encoder
}

Expand Down

0 comments on commit e2fff70

Please sign in to comment.