Use bytes crate for zerocopy and memory re-use (#182)

* Use bytes. Not yet zerocopy everywhere but compiles

* Actually zerocopy

* Actually zerocopy

* Not actually storing the torrent on disk now
This commit is contained in:
Igor Katson 2024-08-14 12:08:46 +01:00 committed by GitHub
parent 3cc9e444b1
commit c7ed475f54
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
20 changed files with 182 additions and 95 deletions

View file

@ -779,7 +779,7 @@ impl<'a> PeerConnectionHandler for &'a PeerHandler {
.context("on_download_request")?;
}
Message::Bitfield(b) => self
.on_bitfield(b.clone_to_owned())
.on_bitfield(b.clone_to_owned(None))
.context("on_bitfield")?,
Message::Choke => self.on_i_am_choked(),
Message::Unchoke => self.on_i_am_unchoked(),
@ -1127,7 +1127,7 @@ impl PeerHandler {
}
self.state
.peers
.update_bitfield_from_vec(self.addr, bitfield.0);
.update_bitfield_from_vec(self.addr, bitfield.0.to_vec().into_boxed_slice());
self.on_bitfield_notify.notify_waiters();
Ok(())
}
@ -1480,7 +1480,7 @@ impl PeerHandler {
let state = self.state.clone();
let addr = self.addr;
let counters = self.counters.clone();
let piece = piece.clone_to_owned();
let piece = piece.clone_to_owned(None);
let tx = self.tx.clone();
let span = tracing::error_span!("deferred_write");