Box<[u8]> instead of Vec<u8> for ByteBufOwned
This commit is contained in:
parent
d9ec702f59
commit
deee41cd93
23 changed files with 106 additions and 124 deletions
|
|
@ -57,7 +57,7 @@ use std::{
|
|||
|
||||
use anyhow::{bail, Context};
|
||||
use backoff::backoff::Backoff;
|
||||
use buffers::{ByteBuf, ByteString};
|
||||
use buffers::{ByteBuf, ByteBufOwned};
|
||||
use clone_to_owned::CloneToOwned;
|
||||
use futures::{stream::FuturesUnordered, StreamExt};
|
||||
use itertools::Itertools;
|
||||
|
|
@ -130,7 +130,7 @@ fn dummy_file() -> anyhow::Result<std::fs::File> {
|
|||
}
|
||||
|
||||
fn make_piece_bitfield(lengths: &Lengths) -> BF {
|
||||
BF::from_vec(vec![0; lengths.piece_bitfield_bytes()])
|
||||
BF::from_boxed_slice(vec![0; lengths.piece_bitfield_bytes()].into_boxed_slice())
|
||||
}
|
||||
|
||||
pub(crate) struct TorrentStateLocked {
|
||||
|
|
@ -485,7 +485,7 @@ impl TorrentStateLive {
|
|||
&self.meta
|
||||
}
|
||||
|
||||
pub fn info(&self) -> &TorrentMetaV1Info<ByteString> {
|
||||
pub fn info(&self) -> &TorrentMetaV1Info<ByteBufOwned> {
|
||||
&self.meta.info
|
||||
}
|
||||
pub fn info_hash(&self) -> Id20 {
|
||||
|
|
@ -1047,7 +1047,7 @@ impl PeerHandler {
|
|||
self.on_bitfield_notify.notify_waiters();
|
||||
}
|
||||
|
||||
fn on_bitfield(&self, bitfield: ByteString) -> anyhow::Result<()> {
|
||||
fn on_bitfield(&self, bitfield: ByteBufOwned) -> anyhow::Result<()> {
|
||||
if bitfield.len() != self.state.lengths.piece_bitfield_bytes() {
|
||||
anyhow::bail!(
|
||||
"dropping peer as its bitfield has unexpected size. Got {}, expected {}",
|
||||
|
|
|
|||
|
|
@ -198,7 +198,7 @@ impl LivePeerState {
|
|||
LivePeerState {
|
||||
peer_id,
|
||||
peer_interested: false,
|
||||
bitfield: BF::new(),
|
||||
bitfield: BF::default(),
|
||||
inflight_requests: Default::default(),
|
||||
tx,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -81,9 +81,9 @@ impl PeerStates {
|
|||
prev
|
||||
})
|
||||
}
|
||||
pub fn update_bitfield_from_vec(&self, handle: PeerHandle, bitfield: Vec<u8>) -> Option<()> {
|
||||
pub fn update_bitfield_from_vec(&self, handle: PeerHandle, bitfield: Box<[u8]>) -> Option<()> {
|
||||
self.with_live_mut(handle, "update_bitfield_from_vec", |live| {
|
||||
live.bitfield = BF::from_vec(bitfield);
|
||||
live.bitfield = BF::from_boxed_slice(bitfield);
|
||||
})
|
||||
}
|
||||
pub fn mark_peer_connecting(&self, h: PeerHandle) -> anyhow::Result<(PeerRx, PeerTx)> {
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ use std::time::Duration;
|
|||
|
||||
use anyhow::bail;
|
||||
use anyhow::Context;
|
||||
use buffers::ByteString;
|
||||
use buffers::ByteBufOwned;
|
||||
use futures::future::BoxFuture;
|
||||
use futures::FutureExt;
|
||||
use librqbit_core::hash_id::Id20;
|
||||
|
|
@ -78,7 +78,7 @@ pub(crate) struct ManagedTorrentOptions {
|
|||
}
|
||||
|
||||
pub struct ManagedTorrentInfo {
|
||||
pub info: TorrentMetaV1Info<ByteString>,
|
||||
pub info: TorrentMetaV1Info<ByteBufOwned>,
|
||||
pub info_hash: Id20,
|
||||
pub out_dir: PathBuf,
|
||||
pub(crate) spawner: BlockingSpawner,
|
||||
|
|
@ -410,7 +410,7 @@ impl ManagedTorrent {
|
|||
}
|
||||
|
||||
pub struct ManagedTorrentBuilder {
|
||||
info: TorrentMetaV1Info<ByteString>,
|
||||
info: TorrentMetaV1Info<ByteBufOwned>,
|
||||
info_hash: Id20,
|
||||
output_folder: PathBuf,
|
||||
force_tracker_interval: Option<Duration>,
|
||||
|
|
@ -425,7 +425,7 @@ pub struct ManagedTorrentBuilder {
|
|||
|
||||
impl ManagedTorrentBuilder {
|
||||
pub fn new<P: AsRef<Path>>(
|
||||
info: TorrentMetaV1Info<ByteString>,
|
||||
info: TorrentMetaV1Info<ByteBufOwned>,
|
||||
info_hash: Id20,
|
||||
output_folder: P,
|
||||
) -> Self {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue