diff options
| author | The8472 <git@infinite-source.de> | 2020-01-25 15:01:39 +0100 |
|---|---|---|
| committer | The8472 <git@infinite-source.de> | 2020-09-03 20:59:26 +0200 |
| commit | 0d2d0334152f0025b00a826482f130f499e7d627 (patch) | |
| tree | 1cc9212f97e4d0eeb7f325bc3151de009c8286f7 /library/alloc/src | |
| parent | 9596e5a2f23771bdbf68b2872b26cce715c8011e (diff) | |
| download | rust-0d2d0334152f0025b00a826482f130f499e7d627.tar.gz rust-0d2d0334152f0025b00a826482f130f499e7d627.zip | |
replace unsafe ptr::write with deref-write, benchmarks show no difference
Diffstat (limited to 'library/alloc/src')
| -rw-r--r-- | library/alloc/src/vec.rs | 14 |
1 files changed, 4 insertions, 10 deletions
diff --git a/library/alloc/src/vec.rs b/library/alloc/src/vec.rs index 9b7f2af3ba9..d2f92b7c008 100644 --- a/library/alloc/src/vec.rs +++ b/library/alloc/src/vec.rs @@ -2086,11 +2086,8 @@ impl<T> Extend<T> for Vec<T> { <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 - let other = SpecFrom::from_iter(iter.into_iter()); - // replace self, don't run drop since self was empty - unsafe { - ptr::write(self, other); - } + // and overwrite self + *self = SpecFrom::from_iter(iter.into_iter()); } } @@ -2544,11 +2541,8 @@ impl<'a, T: 'a + Copy> Extend<&'a T> for Vec<T> { self.spec_extend(iter.into_iter()) } else { // if self has no allocation then use the more powerful from_iter specializations - let other = SpecFrom::from_iter(iter.into_iter()); - // replace self, don't run drop since self was empty - unsafe { - ptr::write(self, other); - } + // and overwrite self + *self = SpecFrom::from_iter(iter.into_iter()); } } |
