Skip to content

Commit c0f8b08

Browse files
committed
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.
1 parent 63c4065 commit c0f8b08

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

src/libcollections/vec.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ use borrow::ToOwned;
6666
use core::cmp::Ordering;
6767
use core::fmt;
6868
use core::hash::{self, Hash};
69-
use core::intrinsics::{arith_offset, assume, needs_drop};
69+
use core::intrinsics::{arith_offset, assume};
7070
use core::iter::FromIterator;
7171
use core::mem;
7272
use core::ops::{Index, IndexMut};
@@ -1471,13 +1471,8 @@ impl<T> Drop for Vec<T> {
14711471
fn drop(&mut self) {
14721472
if self.buf.unsafe_no_drop_flag_needs_drop() {
14731473
unsafe {
1474-
// The branch on needs_drop() is an -O1 performance optimization.
1475-
// Without the branch, dropping Vec<u8> takes linear time.
1476-
if needs_drop::<T>() {
1477-
for x in self.iter_mut() {
1478-
ptr::drop_in_place(x);
1479-
}
1480-
}
1474+
// use drop for [T]
1475+
ptr::drop_in_place(&mut self[..]);
14811476
}
14821477
}
14831478
// RawVec handles deallocation

0 commit comments

Comments
 (0)