From c0f8b085942c0c914c3c9d175303c23e1b4158e3 Mon Sep 17 00:00:00 2001 From: Ulrik Sverdrup Date: Wed, 2 Mar 2016 17:46:54 +0100 Subject: [PATCH] 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. --- src/libcollections/vec.rs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index ae442e155c0..e010c32f8ea 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -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 Drop for Vec { 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 takes linear time. - if needs_drop::() { - for x in self.iter_mut() { - ptr::drop_in_place(x); - } - } + // use drop for [T] + ptr::drop_in_place(&mut self[..]); } } // RawVec handles deallocation -- 2.44.0