Skip to content

Commit 0d2d033

Browse files
committed
replace unsafe ptr::write with deref-write, benchmarks show no difference
1 parent 9596e5a commit 0d2d033

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

library/alloc/src/vec.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2086,11 +2086,8 @@ impl<T> Extend<T> for Vec<T> {
20862086
<Self as SpecExtend<T, I::IntoIter>>::spec_extend(self, iter.into_iter())
20872087
} else {
20882088
// if self has no allocation then use the more powerful from_iter specializations
2089-
let other = SpecFrom::from_iter(iter.into_iter());
2090-
// replace self, don't run drop since self was empty
2091-
unsafe {
2092-
ptr::write(self, other);
2093-
}
2089+
// and overwrite self
2090+
*self = SpecFrom::from_iter(iter.into_iter());
20942091
}
20952092
}
20962093

@@ -2544,11 +2541,8 @@ impl<'a, T: 'a + Copy> Extend<&'a T> for Vec<T> {
25442541
self.spec_extend(iter.into_iter())
25452542
} else {
25462543
// if self has no allocation then use the more powerful from_iter specializations
2547-
let other = SpecFrom::from_iter(iter.into_iter());
2548-
// replace self, don't run drop since self was empty
2549-
unsafe {
2550-
ptr::write(self, other);
2551-
}
2544+
// and overwrite self
2545+
*self = SpecFrom::from_iter(iter.into_iter());
25522546
}
25532547
}
25542548

0 commit comments

Comments
 (0)