migrate everything to using mem::needs_drop
This commit is contained in:
parent
892df1db60
commit
e847d46bcb
|
@ -32,6 +32,7 @@
|
||||||
#![feature(core_intrinsics)]
|
#![feature(core_intrinsics)]
|
||||||
#![feature(dropck_eyepatch)]
|
#![feature(dropck_eyepatch)]
|
||||||
#![feature(generic_param_attrs)]
|
#![feature(generic_param_attrs)]
|
||||||
|
#![feature(needs_drop)]
|
||||||
#![cfg_attr(stage0, feature(staged_api))]
|
#![cfg_attr(stage0, feature(staged_api))]
|
||||||
#![cfg_attr(test, feature(test))]
|
#![cfg_attr(test, feature(test))]
|
||||||
|
|
||||||
|
@ -82,7 +83,7 @@ impl<T> TypedArenaChunk<T> {
|
||||||
unsafe fn destroy(&mut self, len: usize) {
|
unsafe fn destroy(&mut self, len: usize) {
|
||||||
// The branch on needs_drop() is an -O1 performance optimization.
|
// The branch on needs_drop() is an -O1 performance optimization.
|
||||||
// Without the branch, dropping TypedArena<u8> takes linear time.
|
// Without the branch, dropping TypedArena<u8> takes linear time.
|
||||||
if intrinsics::needs_drop::<T>() {
|
if mem::needs_drop::<T>() {
|
||||||
let mut start = self.start();
|
let mut start = self.start();
|
||||||
// Destroy all allocated objects.
|
// Destroy all allocated objects.
|
||||||
for _ in 0..len {
|
for _ in 0..len {
|
||||||
|
@ -350,7 +351,7 @@ impl DroplessArena {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn alloc<T>(&self, object: T) -> &mut T {
|
pub fn alloc<T>(&self, object: T) -> &mut T {
|
||||||
unsafe {
|
unsafe {
|
||||||
assert!(!intrinsics::needs_drop::<T>());
|
assert!(!mem::needs_drop::<T>());
|
||||||
assert!(mem::size_of::<T>() != 0);
|
assert!(mem::size_of::<T>() != 0);
|
||||||
|
|
||||||
self.align_for::<T>();
|
self.align_for::<T>();
|
||||||
|
@ -379,9 +380,7 @@ impl DroplessArena {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn alloc_slice<T>(&self, slice: &[T]) -> &mut [T]
|
pub fn alloc_slice<T>(&self, slice: &[T]) -> &mut [T]
|
||||||
where T: Copy {
|
where T: Copy {
|
||||||
unsafe {
|
assert!(!mem::needs_drop::<T>());
|
||||||
assert!(!intrinsics::needs_drop::<T>());
|
|
||||||
}
|
|
||||||
assert!(mem::size_of::<T>() != 0);
|
assert!(mem::size_of::<T>() != 0);
|
||||||
assert!(slice.len() != 0);
|
assert!(slice.len() != 0);
|
||||||
self.align_for::<T>();
|
self.align_for::<T>();
|
||||||
|
|
|
@ -12,9 +12,8 @@ use alloc::heap::{allocate, deallocate};
|
||||||
|
|
||||||
use cmp;
|
use cmp;
|
||||||
use hash::{BuildHasher, Hash, Hasher};
|
use hash::{BuildHasher, Hash, Hasher};
|
||||||
use intrinsics::needs_drop;
|
|
||||||
use marker;
|
use marker;
|
||||||
use mem::{align_of, size_of};
|
use mem::{align_of, size_of, needs_drop};
|
||||||
use mem;
|
use mem;
|
||||||
use ops::{Deref, DerefMut};
|
use ops::{Deref, DerefMut};
|
||||||
use ptr::{self, Unique, Shared};
|
use ptr::{self, Unique, Shared};
|
||||||
|
|
|
@ -281,6 +281,7 @@
|
||||||
#![feature(linkage)]
|
#![feature(linkage)]
|
||||||
#![feature(macro_reexport)]
|
#![feature(macro_reexport)]
|
||||||
#![feature(needs_panic_runtime)]
|
#![feature(needs_panic_runtime)]
|
||||||
|
#![feature(needs_drop)]
|
||||||
#![feature(never_type)]
|
#![feature(never_type)]
|
||||||
#![feature(num_bits_bytes)]
|
#![feature(num_bits_bytes)]
|
||||||
#![feature(old_wrapping)]
|
#![feature(old_wrapping)]
|
||||||
|
|
|
@ -12,9 +12,10 @@
|
||||||
#![unstable(feature = "thread_local_internals", issue = "0")]
|
#![unstable(feature = "thread_local_internals", issue = "0")]
|
||||||
|
|
||||||
use cell::{Cell, UnsafeCell};
|
use cell::{Cell, UnsafeCell};
|
||||||
use intrinsics;
|
use mem;
|
||||||
use ptr;
|
use ptr;
|
||||||
|
|
||||||
|
|
||||||
pub struct Key<T> {
|
pub struct Key<T> {
|
||||||
inner: UnsafeCell<Option<T>>,
|
inner: UnsafeCell<Option<T>>,
|
||||||
|
|
||||||
|
@ -37,7 +38,7 @@ impl<T> Key<T> {
|
||||||
|
|
||||||
pub fn get(&'static self) -> Option<&'static UnsafeCell<Option<T>>> {
|
pub fn get(&'static self) -> Option<&'static UnsafeCell<Option<T>>> {
|
||||||
unsafe {
|
unsafe {
|
||||||
if intrinsics::needs_drop::<T>() && self.dtor_running.get() {
|
if mem::needs_drop::<T>() && self.dtor_running.get() {
|
||||||
return None
|
return None
|
||||||
}
|
}
|
||||||
self.register_dtor();
|
self.register_dtor();
|
||||||
|
@ -46,7 +47,7 @@ impl<T> Key<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe fn register_dtor(&self) {
|
unsafe fn register_dtor(&self) {
|
||||||
if !intrinsics::needs_drop::<T>() || self.dtor_registered.get() {
|
if !mem::needs_drop::<T>() || self.dtor_registered.get() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
|
|
||||||
use cell::{Cell, UnsafeCell};
|
use cell::{Cell, UnsafeCell};
|
||||||
use fmt;
|
use fmt;
|
||||||
use intrinsics;
|
use mem;
|
||||||
use ptr;
|
use ptr;
|
||||||
|
|
||||||
pub struct Key<T> {
|
pub struct Key<T> {
|
||||||
|
@ -44,7 +44,7 @@ impl<T> Key<T> {
|
||||||
|
|
||||||
pub fn get(&'static self) -> Option<&'static UnsafeCell<Option<T>>> {
|
pub fn get(&'static self) -> Option<&'static UnsafeCell<Option<T>>> {
|
||||||
unsafe {
|
unsafe {
|
||||||
if intrinsics::needs_drop::<T>() && self.dtor_running.get() {
|
if mem::needs_drop::<T>() && self.dtor_running.get() {
|
||||||
return None
|
return None
|
||||||
}
|
}
|
||||||
self.register_dtor();
|
self.register_dtor();
|
||||||
|
@ -53,7 +53,7 @@ impl<T> Key<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe fn register_dtor(&self) {
|
unsafe fn register_dtor(&self) {
|
||||||
if !intrinsics::needs_drop::<T>() || self.dtor_registered.get() {
|
if !mem::needs_drop::<T>() || self.dtor_registered.get() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue