Use `io::sink` rather than our custom `EmptyWrite` utility

This commit is contained in:
Matt Corallo 2023-09-12 17:45:08 +00:00
parent a0ade883b6
commit 5e0209569c
5 changed files with 6 additions and 31 deletions

View File

@ -637,7 +637,7 @@ mod benches {
use super::Block; use super::Block;
use crate::consensus::{deserialize, Decodable, Encodable}; use crate::consensus::{deserialize, Decodable, Encodable};
use crate::EmptyWrite; use crate::io::sink;
#[bench] #[bench]
pub fn bench_stream_reader(bh: &mut Bencher) { pub fn bench_stream_reader(bh: &mut Bencher) {
@ -674,7 +674,7 @@ mod benches {
let block: Block = deserialize(&raw_block[..]).unwrap(); let block: Block = deserialize(&raw_block[..]).unwrap();
bh.iter(|| { bh.iter(|| {
let size = block.consensus_encode(&mut EmptyWrite); let size = block.consensus_encode(&mut sink());
black_box(&size); black_box(&size);
}); });
} }

View File

@ -2112,7 +2112,7 @@ mod benches {
use super::Transaction; use super::Transaction;
use crate::consensus::{deserialize, Encodable}; use crate::consensus::{deserialize, Encodable};
use crate::EmptyWrite; use crate::io::sink;
const SOME_TX: &str = "0100000001a15d57094aa7a21a28cb20b59aab8fc7d1149a3bdbcddba9c622e4f5f6a99ece010000006c493046022100f93bb0e7d8db7bd46e40132d1f8242026e045f03a0efe71bbb8e3f475e970d790221009337cd7f1f929f00cc6ff01f03729b069a7c21b59b1736ddfee5db5946c5da8c0121033b9b137ee87d5a812d6f506efdd37f0affa7ffc310711c06c7f3e097c9447c52ffffffff0100e1f505000000001976a9140389035a9225b3839e2bbf32d826a1e222031fd888ac00000000"; const SOME_TX: &str = "0100000001a15d57094aa7a21a28cb20b59aab8fc7d1149a3bdbcddba9c622e4f5f6a99ece010000006c493046022100f93bb0e7d8db7bd46e40132d1f8242026e045f03a0efe71bbb8e3f475e970d790221009337cd7f1f929f00cc6ff01f03729b069a7c21b59b1736ddfee5db5946c5da8c0121033b9b137ee87d5a812d6f506efdd37f0affa7ffc310711c06c7f3e097c9447c52ffffffff0100e1f505000000001976a9140389035a9225b3839e2bbf32d826a1e222031fd888ac00000000";
@ -2147,7 +2147,7 @@ mod benches {
let tx: Transaction = deserialize(&raw_tx).unwrap(); let tx: Transaction = deserialize(&raw_tx).unwrap();
bh.iter(|| { bh.iter(|| {
let size = tx.consensus_encode(&mut EmptyWrite); let size = tx.consensus_encode(&mut sink());
black_box(&size); black_box(&size);
}); });
} }

View File

@ -196,27 +196,3 @@ mod prelude {
pub use hex::DisplayHex; pub use hex::DisplayHex;
} }
#[cfg(bench)]
use bench::EmptyWrite;
#[cfg(bench)]
mod bench {
use core::fmt::Arguments;
use crate::io::{IoSlice, Result, Write};
#[derive(Default, Clone, Debug, PartialEq, Eq)]
pub struct EmptyWrite;
impl Write for EmptyWrite {
fn write(&mut self, buf: &[u8]) -> Result<usize> { Ok(buf.len()) }
fn write_vectored(&mut self, bufs: &[IoSlice]) -> Result<usize> {
Ok(bufs.iter().map(|s| s.len()).sum())
}
fn flush(&mut self) -> Result<()> { Ok(()) }
fn write_all(&mut self, _: &[u8]) -> Result<()> { Ok(()) }
fn write_fmt(&mut self, _: Arguments) -> Result<()> { Ok(()) }
}
}

View File

@ -5,10 +5,9 @@
//! This module describes BIP37 Connection Bloom filtering network messages. //! This module describes BIP37 Connection Bloom filtering network messages.
//! //!
use std::io;
use crate::consensus::{encode, Decodable, Encodable, ReadExt}; use crate::consensus::{encode, Decodable, Encodable, ReadExt};
use crate::internal_macros::impl_consensus_encoding; use crate::internal_macros::impl_consensus_encoding;
use crate::io;
/// `filterload` message sets the current bloom filter /// `filterload` message sets the current bloom filter
#[derive(Clone, PartialEq, Eq, Debug)] #[derive(Clone, PartialEq, Eq, Debug)]

View File

@ -36,7 +36,7 @@ pub mod io {
compile_error!("At least one of std or core2 must be enabled"); compile_error!("At least one of std or core2 must be enabled");
#[cfg(feature = "std")] #[cfg(feature = "std")]
pub use std::io::{Read, Write, Cursor, Take, IoSlice, Error, ErrorKind, Result}; pub use std::io::{Read, Write, sink, Cursor, Take, Error, ErrorKind, Result};
#[cfg(not(feature = "std"))] #[cfg(not(feature = "std"))]
pub use core2::io::{Read, Write, Cursor, Take, Error, ErrorKind, Result}; pub use core2::io::{Read, Write, Cursor, Take, Error, ErrorKind, Result};