Skip to content

Commit

Permalink
Use Vec::extend in SmallVec::extend when applicable
Browse files Browse the repository at this point in the history
  • Loading branch information
ljedrz committed Jul 30, 2018
1 parent a3f519d commit 9169934
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/librustc_data_structures/small_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,18 @@ impl<A: Array> FromIterator<A::Element> for SmallVec<A> {

impl<A: Array> Extend<A::Element> for SmallVec<A> {
fn extend<I: IntoIterator<Item=A::Element>>(&mut self, iter: I) {
let iter = iter.into_iter();
self.reserve(iter.size_hint().0);
for el in iter {
self.push(el);
if self.is_array() {
let iter = iter.into_iter();
self.reserve(iter.size_hint().0);

for el in iter {
self.push(el);
}
} else {
match self.0 {
AccumulateVec::Heap(ref mut vec) => vec.extend(iter),
_ => unreachable!()
}
}
}
}
Expand Down

0 comments on commit 9169934

Please sign in to comment.