Merge rust-bitcoin/rust-bitcoin#1071: Optimize `Witness` Serialization
9bf959180b
Optimize Witness Serialization (DanGould) Pull request description: fix #942 > self.to_vec() allocates, it should be possible to avoid it - just feed the items into serializer. based on https://github.com/rust-bitcoin/rust-bitcoin/pull/1068 ACKs for top commit: Kixunil: ACK9bf959180b
apoelstra: ACK9bf959180b
Tree-SHA512: 14553dfed20aee50bb6361d44986b38556cbb3e112e1b4d9e3b401c3da831b6bdf159089966254cf371c225ae929fc78516c96a6114b40a7bc1fda7305295e4a
This commit is contained in:
commit
4f5fcd3b37
|
@ -11,9 +11,6 @@ use crate::prelude::*;
|
|||
use secp256k1::ecdsa;
|
||||
use crate::VarInt;
|
||||
|
||||
#[cfg(feature = "serde")]
|
||||
use serde;
|
||||
|
||||
/// The Witness is the data used to unlock bitcoins since the [segwit upgrade](https://github.com/bitcoin/bips/blob/master/bip-0143.mediawiki)
|
||||
///
|
||||
/// Can be logically seen as an array of byte-arrays `Vec<Vec<u8>>` and indeed you can convert from
|
||||
|
@ -282,8 +279,15 @@ impl serde::Serialize for Witness {
|
|||
where
|
||||
S: serde::Serializer,
|
||||
{
|
||||
let vec: Vec<_> = self.to_vec();
|
||||
serde::Serialize::serialize(&vec, serializer)
|
||||
use serde::ser::SerializeSeq;
|
||||
|
||||
let mut seq = serializer.serialize_seq(Some(self.witness_elements))?;
|
||||
|
||||
for elem in self.iter() {
|
||||
seq.serialize_element(&elem)?;
|
||||
}
|
||||
|
||||
seq.end()
|
||||
}
|
||||
}
|
||||
#[cfg(feature = "serde")]
|
||||
|
|
Loading…
Reference in New Issue