Skip to content

Commit 435219d

Browse files
committed
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
1 parent 7492f76 commit 435219d

File tree

2 files changed

+2
-24
lines changed

2 files changed

+2
-24
lines changed

library/alloc/src/vec.rs

+2-14
Original file line numberDiff line numberDiff line change
@@ -2082,13 +2082,7 @@ impl<'a, T> IntoIterator for &'a mut Vec<T> {
20822082
impl<T> Extend<T> for Vec<T> {
20832083
#[inline]
20842084
fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I) {
2085-
if self.capacity() > 0 {
2086-
<Self as SpecExtend<T, I::IntoIter>>::spec_extend(self, iter.into_iter())
2087-
} else {
2088-
// if self has no allocation then use the more powerful from_iter specializations
2089-
// and overwrite self
2090-
*self = SpecFrom::from_iter(iter.into_iter());
2091-
}
2085+
<Self as SpecExtend<T, I::IntoIter>>::spec_extend(self, iter.into_iter())
20922086
}
20932087

20942088
#[inline]
@@ -2544,13 +2538,7 @@ impl<T> Vec<T> {
25442538
#[stable(feature = "extend_ref", since = "1.2.0")]
25452539
impl<'a, T: 'a + Copy> Extend<&'a T> for Vec<T> {
25462540
fn extend<I: IntoIterator<Item = &'a T>>(&mut self, iter: I) {
2547-
if self.capacity() > 0 {
2548-
self.spec_extend(iter.into_iter())
2549-
} else {
2550-
// if self has no allocation then use the more powerful from_iter specializations
2551-
// and overwrite self
2552-
*self = SpecFrom::from_iter(iter.into_iter());
2553-
}
2541+
self.spec_extend(iter.into_iter())
25542542
}
25552543

25562544
#[inline]

library/alloc/tests/vec.rs

-10
Original file line numberDiff line numberDiff line change
@@ -798,16 +798,6 @@ fn test_from_iter_partially_drained_in_place_specialization() {
798798
assert_eq!(srcptr, sinkptr);
799799
}
800800

801-
#[test]
802-
fn test_extend_in_place_specialization() {
803-
let src: Vec<usize> = vec![0usize; 1];
804-
let srcptr = src.as_ptr();
805-
let mut dst = Vec::new();
806-
dst.extend(src.into_iter());
807-
let dstptr = dst.as_ptr();
808-
assert_eq!(srcptr, dstptr);
809-
}
810-
811801
#[test]
812802
fn test_from_iter_specialization_with_iterator_adapters() {
813803
fn assert_in_place_trait<T: InPlaceIterable>(_: &T) {};

0 commit comments

Comments
 (0)