File tree Expand file tree Collapse file tree 1 file changed +4
-3
lines changed Expand file tree Collapse file tree 1 file changed +4
-3
lines changed Original file line number Diff line number Diff line change @@ -2949,7 +2949,7 @@ pub trait Itertools: Iterator {
29492949 /// itertools::assert_equal(five_smallest, 0..5);
29502950 /// ```
29512951 #[ cfg( feature = "use_alloc" ) ]
2952- fn k_smallest ( mut self , k : usize ) -> VecIntoIter < Self :: Item >
2952+ fn k_smallest ( self , k : usize ) -> VecIntoIter < Self :: Item >
29532953 where
29542954 Self : Sized ,
29552955 Self :: Item : Ord ,
@@ -2963,9 +2963,10 @@ pub trait Itertools: Iterator {
29632963 return Vec :: new ( ) . into_iter ( ) ;
29642964 }
29652965
2966- let mut heap = self . by_ref ( ) . take ( k) . collect :: < BinaryHeap < _ > > ( ) ;
2966+ let mut iter = self . fuse ( ) ;
2967+ let mut heap: BinaryHeap < _ > = iter. by_ref ( ) . take ( k) . collect ( ) ;
29672968
2968- self . for_each ( |i| {
2969+ iter . for_each ( |i| {
29692970 debug_assert_eq ! ( heap. len( ) , k) ;
29702971 // Equivalent to heap.push(min(i, heap.pop())) but more efficient.
29712972 // This should be done with a single `.peek_mut().unwrap()` but
You can’t perform that action at this time.
0 commit comments