Skip to content

Commit

Permalink
fix performance bottleneck with io::Read impl for tinybytes
Browse files Browse the repository at this point in the history
  • Loading branch information
ekump committed Sep 17, 2024
1 parent d08ed8a commit 86d2c0c
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion tinybytes/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ unsafe impl Sync for Bytes {}
impl io::Read for Bytes {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
let bytes_read = cmp::min(buf.len(), self.len());
buf[..bytes_read].copy_from_slice(&self[..bytes_read]);

unsafe {
std::ptr::copy_nonoverlapping(self.as_ptr(), buf.as_mut_ptr(), bytes_read);
}

self.advance(bytes_read);
Ok(bytes_read)
}
Expand Down

0 comments on commit 86d2c0c

Please sign in to comment.