Commit 04e73e5 1 parent 0db3339 commit 04e73e5 Copy full SHA for 04e73e5
File tree 1 file changed +16
-2
lines changed
1 file changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -614,6 +614,8 @@ impl Bound for char {
614
614
}
615
615
}
616
616
617
+ /// Iterator that, given a pair of sorted iterators, merges their items into
618
+ /// a single sorted sequence
617
619
struct MergeIter < I : Iterator > {
618
620
left : I ,
619
621
right : I ,
@@ -692,12 +694,24 @@ where
692
694
}
693
695
694
696
fn size_hint ( & self ) -> ( usize , Option < usize > ) {
697
+ use MergeIterState :: * ;
698
+
695
699
// Fundamentally this is a spicy concatenation, so add the sizes together
700
+ let extra_element = match self . state {
701
+ LeftExhausted => 0 ,
702
+ RightExhausted => 0 ,
703
+ LeftItem ( _) => 1 ,
704
+ RightItem ( _) => 1 ,
705
+ } ;
706
+
696
707
let ( min1, max1) = self . left . size_hint ( ) ;
697
708
let ( min2, max2) = self . right . size_hint ( ) ;
698
709
699
- let min = min1. saturating_add ( min2) ;
700
- let max = max1. and_then ( |max| max. checked_add ( max2?) ) ;
710
+ let min = min1. saturating_add ( min2) . saturating_add ( extra_element) ;
711
+
712
+ let max = max1
713
+ . and_then ( |max| max. checked_add ( max2?) )
714
+ . and_then ( |max| max. checked_add ( extra_element) ) ;
701
715
702
716
( min, max)
703
717
}
You can’t perform that action at this time.
0 commit comments