File tree Expand file tree Collapse file tree 1 file changed +11
-6
lines changed Expand file tree Collapse file tree 1 file changed +11
-6
lines changed Original file line number Diff line number Diff line change @@ -84,13 +84,18 @@ mod private {
84
84
#[ inline]
85
85
fn size_hint ( & self ) -> ( usize , Option < usize > ) {
86
86
let ( _, hi) = self . iter . size_hint ( ) ;
87
- // There are `hi` number of items left in the base iterator. In the best case scenario,
88
- // these items are exactly the same as the ones pending (i.e items seen exactly once so
89
- // far), plus (hi - pending) / 2 pairs of never seen before items.
90
87
let hi = hi. map ( |hi| {
91
- let max_pending = std:: cmp:: min ( self . meta . pending , hi) ;
92
- let max_new = hi. saturating_sub ( self . meta . pending ) / 2 ;
93
- max_pending + max_new
88
+ if hi <= self . meta . pending {
89
+ // fewer or equally many iter-remaining elements than pending elements
90
+ // => at most, each iter-remaining element is matched
91
+ hi
92
+ } else {
93
+ // fewer pending elements than iter-remaining elements
94
+ // => at most:
95
+ // * each pending element is matched
96
+ // * the other iter-remaining elements come in pairs
97
+ self . meta . pending + ( hi - self . meta . pending ) / 2
98
+ }
94
99
} ) ;
95
100
// The lower bound is always 0 since we might only get unique items from now on
96
101
( 0 , hi)
You can’t perform that action at this time.
0 commit comments