Skip to content

Commit

Permalink
bgzf/async: Use NonZeroUsize::MIN
Browse files Browse the repository at this point in the history
  • Loading branch information
zaeleus committed Aug 25, 2024
1 parent 54e6d70 commit 802ed03
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 16 deletions.
12 changes: 4 additions & 8 deletions noodles-bgzf/src/async/reader/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,9 @@ impl Builder {
///
/// ```
/// use std::num::NonZeroUsize;
///
/// use noodles_bgzf as bgzf;
///
/// let worker_count = NonZeroUsize::try_from(1)?;
/// let builder = bgzf::r#async::reader::Builder::default()
/// .set_worker_count(worker_count);
/// # Ok::<_, std::num::TryFromIntError>(())
/// .set_worker_count(NonZeroUsize::MIN);
/// ```
pub fn set_worker_count(mut self, worker_count: NonZeroUsize) -> Self {
self.worker_count = Some(worker_count);
Expand All @@ -48,9 +44,9 @@ impl Builder {
where
R: AsyncRead,
{
let worker_count = self.worker_count.unwrap_or_else(|| {
thread::available_parallelism().unwrap_or_else(|_| NonZeroUsize::new(1).unwrap())
});
let worker_count = self
.worker_count
.unwrap_or_else(|| thread::available_parallelism().unwrap_or(NonZeroUsize::MIN));

Reader {
stream: Some(Inflater::new(reader).try_buffered(worker_count.get())),
Expand Down
12 changes: 4 additions & 8 deletions noodles-bgzf/src/async/writer/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,9 @@ impl Builder {
///
/// ```
/// use std::num::NonZeroUsize;
///
/// use noodles_bgzf as bgzf;
///
/// let worker_count = NonZeroUsize::try_from(1)?;
/// let builder = bgzf::r#async::writer::Builder::default()
/// .set_worker_count(worker_count);
/// # Ok::<_, std::num::TryFromIntError>(())
/// .set_worker_count(NonZeroUsize::MIN);
/// ```
pub fn set_worker_count(mut self, worker_count: NonZeroUsize) -> Self {
self.worker_count = Some(worker_count);
Expand All @@ -73,9 +69,9 @@ impl Builder {
{
let compression_level = self.compression_level.unwrap_or_default();

let worker_count = self.worker_count.unwrap_or_else(|| {
thread::available_parallelism().unwrap_or_else(|_| NonZeroUsize::new(1).unwrap())
});
let worker_count = self
.worker_count
.unwrap_or_else(|| thread::available_parallelism().unwrap_or(NonZeroUsize::MIN));

Writer {
sink: Deflater::new(FramedWrite::new(writer, BlockCodec)).buffer(worker_count.get()),
Expand Down

0 comments on commit 802ed03

Please sign in to comment.