about summary refs log tree commit diff
path: root/library/alloc/src
diff options
context:
space:
mode:
authorThe8472 <git@infinite-source.de>2020-01-25 15:01:39 +0100
committerThe8472 <git@infinite-source.de>2020-09-03 20:59:26 +0200
commit0d2d0334152f0025b00a826482f130f499e7d627 (patch)
tree1cc9212f97e4d0eeb7f325bc3151de009c8286f7 /library/alloc/src
parent9596e5a2f23771bdbf68b2872b26cce715c8011e (diff)
downloadrust-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.rs14
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());
         }
     }