Skip to content

Mark Vec::drop() as #[inline] #102554

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions library/alloc/src/vec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ use core::cmp::Ordering;
use core::convert::TryFrom;
use core::fmt;
use core::hash::{Hash, Hasher};
use core::intrinsics::assume;
use core::intrinsics::{assume, needs_drop};
use core::iter;
#[cfg(not(no_global_oom_handling))]
use core::iter::FromIterator;
Expand Down Expand Up @@ -2913,12 +2913,18 @@ impl<T: Ord, A: Allocator> Ord for Vec<T, A> {

#[stable(feature = "rust1", since = "1.0.0")]
unsafe impl<#[may_dangle] T, A: Allocator> Drop for Vec<T, A> {
#[inline]
fn drop(&mut self) {
unsafe {
// use drop for [T]
// use a raw slice to refer to the elements of the vector as weakest necessary type;
// could avoid questions of validity in certain cases
ptr::drop_in_place(ptr::slice_from_raw_parts_mut(self.as_mut_ptr(), self.len))
if needs_drop::<T>() {
unsafe fn drop_via_slice<T, A: Allocator>(vec: &mut Vec<T, A>) {
unsafe {
// use drop for [T]
// use a raw slice to refer to the elements of the vector as weakest
// necessary type; could avoid questions of validity in certain cases
ptr::drop_in_place(ptr::slice_from_raw_parts_mut(vec.as_mut_ptr(), vec.len))
}
}
unsafe { drop_via_slice(self); }
}
// RawVec handles deallocation
}
Expand Down