Skip to content

Commit

Permalink
document the ExactSizeIterator optimization in choose()
Browse files Browse the repository at this point in the history
  • Loading branch information
kazcw committed Oct 13, 2020
1 parent 7f6eca4 commit dab98b3
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/seq/mod.rs
Expand Up @@ -302,6 +302,9 @@ pub trait IteratorRandom: Iterator + Sized {
let mut consumed = 0;
let mut result = None;

// Handling for this condition outside the loop allows the optimizer to eliminate the loop
// when the Iterator is an ExactSizeIterator. This has a large performance impact on e.g.
// seq_iter_choose_from_1000.
if upper == Some(lower) {
return if lower == 0 {
None
Expand Down

0 comments on commit dab98b3

Please sign in to comment.