File tree Expand file tree Collapse file tree 2 files changed +2
-2
lines changed
Expand file tree Collapse file tree 2 files changed +2
-2
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ You may also find the [Upgrade Guide](https://rust-random.github.io/book/update.
1919- Remove fns ` SeedableRng::from_os_rng ` , ` try_from_os_rng ` (#1674 )
2020- Remove ` Clone ` support for ` StdRng ` , ` ReseedingRng ` (#1677 )
2121- Use ` postcard ` instead of ` bincode ` to test the serde feature (#1693 )
22+ - Avoid excessive allocation in ` IteratorRandom::sample ` when ` amount ` is much larger than iterator size
2223
2324### Additions
2425- Add fns ` IndexedRandom::choose_iter ` , ` choose_weighted_iter ` (#1632 )
Original file line number Diff line number Diff line change @@ -245,8 +245,7 @@ pub trait IteratorRandom: Iterator + Sized {
245245 where
246246 R : Rng + ?Sized ,
247247 {
248- let mut reservoir = Vec :: with_capacity ( amount) ;
249- reservoir. extend ( self . by_ref ( ) . take ( amount) ) ;
248+ let mut reservoir = Vec :: from_iter ( self . by_ref ( ) . take ( amount) ) ;
250249
251250 // Continue unless the iterator was exhausted
252251 //
You can’t perform that action at this time.
0 commit comments