提交 c0f8b085 编写于 作者: U Ulrik Sverdrup

Use ptr::drop_in_place in Vec::drop

Directly use the drop glue for [T]. Still optimizes out in -O1 like with
the `needs_drop` intrinsic.
上级 63c4065a
......@@ -66,7 +66,7 @@
use core::cmp::Ordering;
use core::fmt;
use core::hash::{self, Hash};
use core::intrinsics::{arith_offset, assume, needs_drop};
use core::intrinsics::{arith_offset, assume};
use core::iter::FromIterator;
use core::mem;
use core::ops::{Index, IndexMut};
......@@ -1471,13 +1471,8 @@ impl<T> Drop for Vec<T> {
fn drop(&mut self) {
if self.buf.unsafe_no_drop_flag_needs_drop() {
unsafe {
// The branch on needs_drop() is an -O1 performance optimization.
// Without the branch, dropping Vec<u8> takes linear time.
if needs_drop::<T>() {
for x in self.iter_mut() {
ptr::drop_in_place(x);
}
}
// use drop for [T]
ptr::drop_in_place(&mut self[..]);
}
}
// RawVec handles deallocation
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册