Skip to content

Commit d7a0d1a

Browse files
committed
try to reserve space in the Extend impls
1 parent 7f8b83a commit d7a0d1a

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

src/lib.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,17 +1082,18 @@ impl<H, T> Extend<T> for HeaderVec<H, T> {
10821082
#[inline]
10831083
#[track_caller]
10841084
fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I) {
1085-
iter.into_iter().for_each(|item| self.push(item));
1085+
let iter = iter.into_iter();
1086+
self.reserve(iter.size_hint().0);
1087+
iter.for_each(|item| self.push(item));
10861088
}
10871089
}
10881090

10891091
/// Extend implementation that copies elements out of references before pushing them onto the Vec.
1090-
// Note: from std Vec: not implemented here yet
1091-
// This implementation is specialized for slice iterators, where it uses [`copy_from_slice`] to
1092-
// append the entire slice at once.
10931092
impl<'a, H, T: Copy + 'a> Extend<&'a T> for HeaderVec<H, T> {
10941093
#[track_caller]
10951094
fn extend<I: IntoIterator<Item = &'a T>>(&mut self, iter: I) {
1096-
iter.into_iter().for_each(|item| self.push(*item));
1095+
let iter = iter.into_iter();
1096+
self.reserve(iter.size_hint().0);
1097+
iter.for_each(|item| self.push(*item));
10971098
}
10981099
}

0 commit comments

Comments
 (0)