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

View File

@ -798,16 +798,6 @@ fn test_from_iter_partially_drained_in_place_specialization() {
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]
fn test_from_iter_specialization_with_iterator_adapters() {
fn assert_in_place_trait<T: InPlaceIterable>(_: &T) {};