Skip to content

Commit

Permalink
feat: More efficient implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
fasterthanlime committed Mar 16, 2024
1 parent a34a302 commit b5d6361
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions rc-zip-tokio/src/read_zip.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
use std::{cmp, io, ops::Deref, pin::Pin, sync::Arc, task};
use std::{
cmp, io,
ops::Deref,
pin::Pin,
sync::Arc,
task::{self, Context, Poll},
};

use futures::future::BoxFuture;
use positioned_io::{RandomAccessFile, ReadAt, Size};
Expand Down Expand Up @@ -278,9 +284,9 @@ pub struct AsyncRandomAccessFileCursor {
impl AsyncRead for AsyncRandomAccessFileCursor {
fn poll_read(
mut self: Pin<&mut Self>,
cx: &mut task::Context<'_>,
cx: &mut Context<'_>,
buf: &mut ReadBuf<'_>,
) -> task::Poll<io::Result<()>> {
) -> Poll<io::Result<()>> {
match &mut self.state {
ARAFCState::Idle { .. } => {
let mut core = match std::mem::take(&mut self.state) {
Expand All @@ -298,23 +304,23 @@ impl AsyncRead for AsyncRandomAccessFileCursor {
}
ARAFCState::Reading { fut } => {
let (read, core) = match fut.as_mut().poll(cx) {
task::Poll::Ready(Ok(r)) => r,
task::Poll::Ready(Err(e)) => {
return task::Poll::Ready(Err(io::Error::new(
Poll::Ready(Ok(r)) => r,
Poll::Ready(Err(e)) => {
return Poll::Ready(Err(io::Error::new(

Check warning on line 309 in rc-zip-tokio/src/read_zip.rs

View check run for this annotation

Codecov / codecov/patch

rc-zip-tokio/src/read_zip.rs#L308-L309

Added lines #L308 - L309 were not covered by tests
io::ErrorKind::Other,
e.to_string(),
)))
}
task::Poll::Pending => return task::Poll::Pending,
Poll::Pending => return Poll::Pending,
};
match read {
Ok(read) => {
self.pos += read as u64;
buf.put_slice(&core.inner_buf[..read]);
self.state = ARAFCState::Idle(core);
task::Poll::Ready(Ok(()))
Poll::Ready(Ok(()))
}
Err(e) => task::Poll::Ready(Err(e)),
Err(e) => Poll::Ready(Err(e)),

Check warning on line 323 in rc-zip-tokio/src/read_zip.rs

View check run for this annotation

Codecov / codecov/patch

rc-zip-tokio/src/read_zip.rs#L323

Added line #L323 was not covered by tests
}
}
ARAFCState::Transitioning => unreachable!(),
Expand Down

0 comments on commit b5d6361

Please sign in to comment.