Skip to content

Commit

Permalink
bgzf/multithreaded_reader: Directly copy from the block buffer when t…
Browse files Browse the repository at this point in the history
…he given buffer can be completely filled
  • Loading branch information
zaeleus committed May 1, 2024
1 parent 5bc27fe commit b15e790
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 12 additions & 0 deletions noodles-bgzf/src/multithreaded_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,18 @@ where
self.consume(amt);
Ok(amt)
}

fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> {
use super::reader::default_read_exact;

if let Some(src) = self.buffer.block.data().as_ref().get(..buf.len()) {
buf.copy_from_slice(src);
self.consume(src.len());
Ok(())
} else {
default_read_exact(self, buf)
}
}
}

impl<R> BufRead for MultithreadedReader<R>
Expand Down
2 changes: 1 addition & 1 deletion noodles-bgzf/src/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ where
}
}

fn default_read_exact<R>(reader: &mut R, mut buf: &mut [u8]) -> io::Result<()>
pub(crate) fn default_read_exact<R>(reader: &mut R, mut buf: &mut [u8]) -> io::Result<()>
where
R: Read,
{
Expand Down

0 comments on commit b15e790

Please sign in to comment.