File tree Expand file tree Collapse file tree 7 files changed +23
-29
lines changed Expand file tree Collapse file tree 7 files changed +23
-29
lines changed Original file line number Diff line number Diff line change @@ -10,9 +10,9 @@ impl<T: Ord> Extend<T> for BinaryHeap<T> {
1010 stream : S ,
1111 ) -> Pin < Box < dyn Future < Output = ( ) > + ' a > > {
1212 let stream = stream. into_stream ( ) ;
13- //TODO: Add this back in when size_hint is added to Stream/StreamExt
14- //let (lower_bound, _) = stream.size_hint();
15- //self.reserve(lower_bound);
13+
14+ self . reserve ( stream. size_hint ( ) . 0 ) ;
15+
1616 Box :: pin ( stream. for_each ( move |item| self . push ( item) ) )
1717 }
1818}
Original file line number Diff line number Diff line change @@ -23,13 +23,12 @@ where
2323 // hint lower bound if the map is empty. Otherwise reserve half the hint (rounded up), so
2424 // the map will only resize twice in the worst case.
2525
26- //TODO: Add this back in when size_hint is added to Stream/StreamExt
27- //let reserve = if self.is_empty() {
28- // stream.size_hint().0
29- //} else {
30- // (stream.size_hint().0 + 1) / 2
31- //};
32- //self.reserve(reserve);
26+ let additional = if self . is_empty ( ) {
27+ stream. size_hint ( ) . 0
28+ } else {
29+ ( stream. size_hint ( ) . 0 + 1 ) / 2
30+ } ;
31+ self . reserve ( additional) ;
3332
3433 Box :: pin ( stream. for_each ( move |( k, v) | {
3534 self . insert ( k, v) ;
Original file line number Diff line number Diff line change @@ -26,13 +26,12 @@ where
2626 // hint lower bound if the map is empty. Otherwise reserve half the hint (rounded up), so
2727 // the map will only resize twice in the worst case.
2828
29- //TODO: Add this back in when size_hint is added to Stream/StreamExt
30- //let reserve = if self.is_empty() {
31- // stream.size_hint().0
32- //} else {
33- // (stream.size_hint().0 + 1) / 2
34- //};
35- //self.reserve(reserve);
29+ let additional = if self . is_empty ( ) {
30+ stream. size_hint ( ) . 0
31+ } else {
32+ ( stream. size_hint ( ) . 0 + 1 ) / 2
33+ } ;
34+ self . reserve ( additional) ;
3635
3736 Box :: pin ( stream. for_each ( move |item| {
3837 self . insert ( item) ;
Original file line number Diff line number Diff line change @@ -10,9 +10,6 @@ impl<T> Extend<T> for LinkedList<T> {
1010 stream : S ,
1111 ) -> Pin < Box < dyn Future < Output = ( ) > + ' a > > {
1212 let stream = stream. into_stream ( ) ;
13- //TODO: Add this back in when size_hint is added to Stream/StreamExt
14- //let (lower_bound, _) = stream.size_hint();
15- //self.reserve(lower_bound);
1613 Box :: pin ( stream. for_each ( move |item| self . push_back ( item) ) )
1714 }
1815}
Original file line number Diff line number Diff line change @@ -10,9 +10,9 @@ impl<T> Extend<T> for VecDeque<T> {
1010 stream : S ,
1111 ) -> Pin < Box < dyn Future < Output = ( ) > + ' a > > {
1212 let stream = stream. into_stream ( ) ;
13- //TODO: Add this back in when size_hint is added to Stream/StreamExt
14- //let (lower_bound, _) = stream.size_hint();
15- //self.reserve(lower_bound);
13+
14+ self . reserve ( stream. size_hint ( ) . 0 ) ;
15+
1616 Box :: pin ( stream. for_each ( move |item| self . push_back ( item) ) )
1717 }
1818}
Original file line number Diff line number Diff line change @@ -10,9 +10,8 @@ impl Extend<char> for String {
1010 stream : S ,
1111 ) -> Pin < Box < dyn Future < Output = ( ) > + ' a > > {
1212 let stream = stream. into_stream ( ) ;
13- //TODO: Add this back in when size_hint is added to Stream/StreamExt
14- // let (lower_bound, _) = stream.size_hint();
15- // self.reserve(lower_bound);
13+
14+ self . reserve ( stream. size_hint ( ) . 0 ) ;
1615
1716 Box :: pin ( stream. for_each ( move |c| self . push ( c) ) )
1817 }
Original file line number Diff line number Diff line change @@ -9,9 +9,9 @@ impl<T> Extend<T> for Vec<T> {
99 stream : S ,
1010 ) -> Pin < Box < dyn Future < Output = ( ) > + ' a > > {
1111 let stream = stream. into_stream ( ) ;
12- //TODO: Add this back in when size_hint is added to Stream/StreamExt
13- //let (lower_bound, _) = stream.size_hint();
14- //self.reserve(lower_bound);
12+
13+ self . reserve ( stream. size_hint ( ) . 0 ) ;
14+
1515 Box :: pin ( stream. for_each ( move |item| self . push ( item) ) )
1616 }
1717}
You can’t perform that action at this time.
0 commit comments