Skip to content

Commit bc7199f

Browse files
committed
replace unsafe ptr::write with mem::replace, benchmarks show no difference
1 parent e300c19 commit bc7199f

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

src/liballoc/vec.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1990,11 +1990,8 @@ impl<T> Extend<T> for Vec<T> {
19901990
<Self as SpecExtend<T, I::IntoIter>>::spec_extend(self, iter.into_iter())
19911991
} else {
19921992
// if self has no allocation then use the more powerful from_iter specializations
1993-
let other = SpecFrom::from_iter(iter.into_iter());
1994-
// replace self, don't run drop since self was empty
1995-
unsafe {
1996-
ptr::write(self, other);
1997-
}
1993+
// and overwrite self
1994+
mem::replace(self, SpecFrom::from_iter(iter.into_iter()));
19981995
}
19991996
}
20001997
}
@@ -2440,11 +2437,8 @@ impl<'a, T: 'a + Copy> Extend<&'a T> for Vec<T> {
24402437
self.spec_extend(iter.into_iter())
24412438
} else {
24422439
// if self has no allocation then use the more powerful from_iter specializations
2443-
let other = SpecFrom::from_iter(iter.into_iter());
2444-
// replace self, don't run drop since self was empty
2445-
unsafe {
2446-
ptr::write(self, other);
2447-
}
2440+
// and overwrite self
2441+
mem::replace(self, SpecFrom::from_iter(iter.into_iter()));
24482442
}
24492443
}
24502444
}

0 commit comments

Comments
 (0)