diff --git a/src/collections/binary_heap/extend.rs b/src/collections/binary_heap/extend.rs index 8538f9b0..4503fe39 100644 --- a/src/collections/binary_heap/extend.rs +++ b/src/collections/binary_heap/extend.rs @@ -10,9 +10,9 @@ impl Extend for BinaryHeap { stream: S, ) -> Pin + 'a>> { let stream = stream.into_stream(); - //TODO: Add this back in when size_hint is added to Stream/StreamExt - //let (lower_bound, _) = stream.size_hint(); - //self.reserve(lower_bound); + + self.reserve(stream.size_hint().0); + Box::pin(stream.for_each(move |item| self.push(item))) } } diff --git a/src/collections/hash_map/extend.rs b/src/collections/hash_map/extend.rs index 5f96b8ab..c34bb9ed 100644 --- a/src/collections/hash_map/extend.rs +++ b/src/collections/hash_map/extend.rs @@ -23,13 +23,12 @@ where // hint lower bound if the map is empty. Otherwise reserve half the hint (rounded up), so // the map will only resize twice in the worst case. - //TODO: Add this back in when size_hint is added to Stream/StreamExt - //let reserve = if self.is_empty() { - // stream.size_hint().0 - //} else { - // (stream.size_hint().0 + 1) / 2 - //}; - //self.reserve(reserve); + let additional = if self.is_empty() { + stream.size_hint().0 + } else { + (stream.size_hint().0 + 1) / 2 + }; + self.reserve(additional); Box::pin(stream.for_each(move |(k, v)| { self.insert(k, v); diff --git a/src/collections/hash_set/extend.rs b/src/collections/hash_set/extend.rs index 72400e11..123e844e 100644 --- a/src/collections/hash_set/extend.rs +++ b/src/collections/hash_set/extend.rs @@ -26,13 +26,12 @@ where // hint lower bound if the map is empty. Otherwise reserve half the hint (rounded up), so // the map will only resize twice in the worst case. - //TODO: Add this back in when size_hint is added to Stream/StreamExt - //let reserve = if self.is_empty() { - // stream.size_hint().0 - //} else { - // (stream.size_hint().0 + 1) / 2 - //}; - //self.reserve(reserve); + let additional = if self.is_empty() { + stream.size_hint().0 + } else { + (stream.size_hint().0 + 1) / 2 + }; + self.reserve(additional); Box::pin(stream.for_each(move |item| { self.insert(item); diff --git a/src/collections/linked_list/extend.rs b/src/collections/linked_list/extend.rs index 567a92d3..63a1a97c 100644 --- a/src/collections/linked_list/extend.rs +++ b/src/collections/linked_list/extend.rs @@ -10,9 +10,6 @@ impl Extend for LinkedList { stream: S, ) -> Pin + 'a>> { let stream = stream.into_stream(); - //TODO: Add this back in when size_hint is added to Stream/StreamExt - //let (lower_bound, _) = stream.size_hint(); - //self.reserve(lower_bound); Box::pin(stream.for_each(move |item| self.push_back(item))) } } diff --git a/src/collections/vec_deque/extend.rs b/src/collections/vec_deque/extend.rs index d034bdcd..17e396ab 100644 --- a/src/collections/vec_deque/extend.rs +++ b/src/collections/vec_deque/extend.rs @@ -10,9 +10,9 @@ impl Extend for VecDeque { stream: S, ) -> Pin + 'a>> { let stream = stream.into_stream(); - //TODO: Add this back in when size_hint is added to Stream/StreamExt - //let (lower_bound, _) = stream.size_hint(); - //self.reserve(lower_bound); + + self.reserve(stream.size_hint().0); + Box::pin(stream.for_each(move |item| self.push_back(item))) } } diff --git a/src/string/extend.rs b/src/string/extend.rs index 72260a54..8572cc3c 100644 --- a/src/string/extend.rs +++ b/src/string/extend.rs @@ -10,9 +10,8 @@ impl Extend for String { stream: S, ) -> Pin + 'a>> { let stream = stream.into_stream(); - //TODO: Add this back in when size_hint is added to Stream/StreamExt - // let (lower_bound, _) = stream.size_hint(); - // self.reserve(lower_bound); + + self.reserve(stream.size_hint().0); Box::pin(stream.for_each(move |c| self.push(c))) } diff --git a/src/vec/extend.rs b/src/vec/extend.rs index ca3373d6..ecf68c83 100644 --- a/src/vec/extend.rs +++ b/src/vec/extend.rs @@ -9,9 +9,9 @@ impl Extend for Vec { stream: S, ) -> Pin + 'a>> { let stream = stream.into_stream(); - //TODO: Add this back in when size_hint is added to Stream/StreamExt - //let (lower_bound, _) = stream.size_hint(); - //self.reserve(lower_bound); + + self.reserve(stream.size_hint().0); + Box::pin(stream.for_each(move |item| self.push(item))) } }