Skip to content

Commit 4d1bce1

Browse files
authored
Rollup merge of rust-lang#41191 - seanmonstar:spec-extend-vec-intoiter, r=alexcrichton
specialize Extend for Vec with IntoIter Before, `vec.extend(&other_vec)` was quite a bit faster than `vec.extend(other_vec)`. This allows extending by consuming a vec to use the same code as extending from a slice.
2 parents a5aa784 + 75e3607 commit 4d1bce1

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/libcollections/vec.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1681,7 +1681,7 @@ impl<T, I> SpecExtend<T, I> for Vec<T>
16811681
vector
16821682
}
16831683

1684-
fn spec_extend(&mut self, iterator: I) {
1684+
default fn spec_extend(&mut self, iterator: I) {
16851685
// This is the case for a TrustedLen iterator.
16861686
let (low, high) = iterator.size_hint();
16871687
if let Some(high_value) = high {
@@ -1728,6 +1728,14 @@ impl<T> SpecExtend<T, IntoIter<T>> for Vec<T> {
17281728
}
17291729
}
17301730

1731+
impl<T> SpecExtend<T, IntoIter<T>> for Vec<T>
1732+
where T: Copy,
1733+
{
1734+
fn spec_extend(&mut self, iterator: IntoIter<T>) {
1735+
self.spec_extend(iterator.as_slice());
1736+
}
1737+
}
1738+
17311739
impl<'a, T: 'a, I> SpecExtend<&'a T, I> for Vec<T>
17321740
where I: Iterator<Item=&'a T>,
17331741
T: Clone,

0 commit comments

Comments
 (0)