diff options
| author | The8472 <git@infinite-source.de> | 2020-08-26 23:24:34 +0200 |
|---|---|---|
| committer | The8472 <git@infinite-source.de> | 2020-09-03 20:59:35 +0200 |
| commit | 435219dd82896e9576ef3f7fbc5c2cf17bae0016 (patch) | |
| tree | cc016d32f32ea6d40689d7afebf36f8c67e74221 | |
| parent | 7492f76f777d2815290d3b8590dc3911df6336de (diff) | |
| download | rust-435219dd82896e9576ef3f7fbc5c2cf17bae0016.tar.gz rust-435219dd82896e9576ef3f7fbc5c2cf17bae0016.zip | |
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
| -rw-r--r-- | library/alloc/src/vec.rs | 16 | ||||
| -rw-r--r-- | library/alloc/tests/vec.rs | 10 |
2 files changed, 2 insertions, 24 deletions
diff --git a/library/alloc/src/vec.rs b/library/alloc/src/vec.rs index dcfd3ecb3d3..2a778e1470d 100644 --- a/library/alloc/src/vec.rs +++ b/library/alloc/src/vec.rs @@ -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] diff --git a/library/alloc/tests/vec.rs b/library/alloc/tests/vec.rs index 47819714cc4..8e66c8a22ce 100644 --- a/library/alloc/tests/vec.rs +++ b/library/alloc/tests/vec.rs @@ -799,16 +799,6 @@ fn test_from_iter_partially_drained_in_place_specialization() { } #[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) {}; let src: Vec<usize> = vec![0usize; 65535]; |
