Skip to content

Commit

Permalink
fix size hint
Browse files Browse the repository at this point in the history
  • Loading branch information
conradludgate committed Aug 7, 2024
1 parent 2384ae2 commit ba2c389
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 29 deletions.
6 changes: 3 additions & 3 deletions benches/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ async fn sleep() {

#[divan::bench_group]
mod futures_unordered {
use futures_buffered::FuturesUnorderedBounded;
use futures::{stream::FuturesUnordered, StreamExt};
use futures_buffered::FuturesUnorderedBounded;

use crate::sleep;

Expand Down Expand Up @@ -71,8 +71,8 @@ mod futures_unordered {

#[divan::bench_group]
mod buffer_unordered {
use futures_buffered::BufferedStreamExt;
use futures::{stream, StreamExt};
use futures_buffered::BufferedStreamExt;

use crate::sleep;

Expand Down Expand Up @@ -107,8 +107,8 @@ mod buffer_unordered {

#[divan::bench_group]
mod buffer_ordered {
use futures_buffered::BufferedStreamExt;
use futures::{stream, StreamExt};
use futures_buffered::BufferedStreamExt;

use crate::sleep;

Expand Down
25 changes: 12 additions & 13 deletions src/buffered/ordered.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,18 @@ where
}

fn size_hint(&self) -> (usize, Option<usize>) {
match &self.stream {
Some(s) => {
let queue_len = self.in_progress_queue.len();
let (lower, upper) = s.size_hint();
let lower = lower.saturating_add(queue_len);
let upper = match upper {
Some(x) => x.checked_add(queue_len),
None => None,
};
(lower, upper)
}
_ => (0, Some(0)),
}
let queue_len = self.in_progress_queue.len();
let (lower, upper) = self
.stream
.as_ref()
.map(|s| s.size_hint())
.unwrap_or((0, Some(0)));
let lower = lower.saturating_add(queue_len);
let upper = match upper {
Some(x) => x.checked_add(queue_len),
None => None,
};
(lower, upper)
}
}

Expand Down
25 changes: 12 additions & 13 deletions src/buffered/unordered.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,19 +116,18 @@ where
}

fn size_hint(&self) -> (usize, Option<usize>) {
match &self.stream {
Some(s) => {
let queue_len = self.in_progress_queue.len();
let (lower, upper) = s.size_hint();
let lower = lower.saturating_add(queue_len);
let upper = match upper {
Some(x) => x.checked_add(queue_len),
None => None,
};
(lower, upper)
}
_ => (0, Some(0)),
}
let queue_len = self.in_progress_queue.len();
let (lower, upper) = self
.stream
.as_ref()
.map(|s| s.size_hint())
.unwrap_or((0, Some(0)));
let lower = lower.saturating_add(queue_len);
let upper = match upper {
Some(x) => x.checked_add(queue_len),
None => None,
};
(lower, upper)
}
}

Expand Down

0 comments on commit ba2c389

Please sign in to comment.