remove empty Vec extend optimization

The optimization meant that every extend code path had to emit llvm
IR for from_iter and extend spec_extend, which likely impacts
compile times while only improving a few edge-cases
This commit is contained in:
The8472 2020-08-26 23:24:34 +02:00
parent 7492f76f77
commit 435219dd82
2 changed files with 2 additions and 24 deletions

View File

@ -2082,13 +2082,7 @@ fn into_iter(self) -> slice::IterMut<'a, T> {
impl<T> Extend<T> for Vec<T> { impl<T> Extend<T> for Vec<T> {
#[inline] #[inline]
fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I) { fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I) {
if self.capacity() > 0 { <Self as SpecExtend<T, I::IntoIter>>::spec_extend(self, iter.into_iter())
<Self as SpecExtend<T, I::IntoIter>>::spec_extend(self, iter.into_iter())
} else {
// if self has no allocation then use the more powerful from_iter specializations
// and overwrite self
*self = SpecFrom::from_iter(iter.into_iter());
}
} }
#[inline] #[inline]
@ -2544,13 +2538,7 @@ pub fn drain_filter<F>(&mut self, filter: F) -> DrainFilter<'_, T, F>
#[stable(feature = "extend_ref", since = "1.2.0")] #[stable(feature = "extend_ref", since = "1.2.0")]
impl<'a, T: 'a + Copy> Extend<&'a T> for Vec<T> { impl<'a, T: 'a + Copy> Extend<&'a T> for Vec<T> {
fn extend<I: IntoIterator<Item = &'a T>>(&mut self, iter: I) { fn extend<I: IntoIterator<Item = &'a T>>(&mut self, iter: I) {
if self.capacity() > 0 { self.spec_extend(iter.into_iter())
self.spec_extend(iter.into_iter())
} else {
// if self has no allocation then use the more powerful from_iter specializations
// and overwrite self
*self = SpecFrom::from_iter(iter.into_iter());
}
} }
#[inline] #[inline]

View File

@ -798,16 +798,6 @@ fn test_from_iter_partially_drained_in_place_specialization() {
assert_eq!(srcptr, sinkptr); assert_eq!(srcptr, sinkptr);
} }
#[test]
fn test_extend_in_place_specialization() {
let src: Vec<usize> = vec![0usize; 1];
let srcptr = src.as_ptr();
let mut dst = Vec::new();
dst.extend(src.into_iter());
let dstptr = dst.as_ptr();
assert_eq!(srcptr, dstptr);
}
#[test] #[test]
fn test_from_iter_specialization_with_iterator_adapters() { fn test_from_iter_specialization_with_iterator_adapters() {
fn assert_in_place_trait<T: InPlaceIterable>(_: &T) {}; fn assert_in_place_trait<T: InPlaceIterable>(_: &T) {};