Skip to content

Commit

Permalink
optimize queue for bytes::Buf::chunks_vectored
Browse files Browse the repository at this point in the history
  • Loading branch information
TimLuq committed Jan 14, 2025
1 parent e0acf36 commit 145458e
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -41,7 +41,7 @@ macros = []
## Exposes structures `ByteQueue` and `StringQueue` for efficient pushing and popping of byte/str data.
queue = []
## Implements traits from `std`.
std = ["alloc"]
std = ["alloc", "bytes_1?/std"]

nightly = []
core_io_borrowed_buf = []
11 changes: 11 additions & 0 deletions src/bytes_1/queue.rs
Original file line number Diff line number Diff line change
@@ -111,4 +111,15 @@ impl bytes::Buf for ByteQueue<'_> {
}
ret.freeze()
}

#[cfg(feature = "std")]
#[inline]
fn chunks_vectored<'a>(&'a self, dst: &mut [std::io::IoSlice<'a>]) -> usize {
let mut i = 0;
for chunk in self.chunks().take(dst.len()) {
dst[i] = std::io::IoSlice::new(chunk.as_slice());
i += 1;
}
i
}
}

0 comments on commit 145458e

Please sign in to comment.