mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-04 01:42:54 +03:00
replace unsafe ptr::write with deref-write, benchmarks show no difference
This commit is contained in:
@@ -2086,11 +2086,8 @@ fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I) {
|
||||
<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 @@ fn extend<I: IntoIterator<Item = &'a T>>(&mut self, iter: I) {
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user