Skip to content

Commit e6c9411

Browse files
k_smallest(0) and variants: consume the iterator
The iterator can have side effects so I think it should be consumed in all cases, even k=0. If there are no side-effect then maybe the compiler will optimize it away.
1 parent 5cf292f commit e6c9411

File tree

2 files changed

+2
-0
lines changed

2 files changed

+2
-0
lines changed

src/k_smallest.rs

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ where
4242
}
4343

4444
if k == 0 {
45+
iter.last();
4546
return Vec::new();
4647
}
4748
let mut iter = iter.fuse();

src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2972,6 +2972,7 @@ pub trait Itertools: Iterator {
29722972
use alloc::collections::BinaryHeap;
29732973

29742974
if k == 0 {
2975+
self.last();
29752976
return Vec::new().into_iter();
29762977
}
29772978

0 commit comments

Comments
 (0)