File tree Expand file tree Collapse file tree 1 file changed +16
-2
lines changed
Expand file tree Collapse file tree 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 {
614614 }
615615}
616616
617+ /// Iterator that, given a pair of sorted iterators, merges their items into
618+ /// a single sorted sequence
617619struct MergeIter < I : Iterator > {
618620 left : I ,
619621 right : I ,
@@ -692,12 +694,24 @@ where
692694 }
693695
694696 fn size_hint ( & self ) -> ( usize , Option < usize > ) {
697+ use MergeIterState :: * ;
698+
695699 // 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+
696707 let ( min1, max1) = self . left . size_hint ( ) ;
697708 let ( min2, max2) = self . right . size_hint ( ) ;
698709
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) ) ;
701715
702716 ( min, max)
703717 }
You can’t perform that action at this time.
0 commit comments