Better function calls
This commit is contained in:
parent
06812c2999
commit
459f7720b9
@ -307,7 +307,9 @@ impl<T: ?Sized> Arc<T> {
|
|||||||
|
|
||||||
if self.inner().weak.fetch_sub(1, Release) == 1 {
|
if self.inner().weak.fetch_sub(1, Release) == 1 {
|
||||||
atomic::fence(Acquire);
|
atomic::fence(Acquire);
|
||||||
deallocate(ptr as *mut u8, size_of_val(&*ptr), align_of_val(&*ptr))
|
deallocate(ptr as *mut u8,
|
||||||
|
size_of_val(&*ptr),
|
||||||
|
align_of_val(&*ptr))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -719,7 +721,11 @@ impl<T: ?Sized> Drop for Weak<T> {
|
|||||||
// ref, which can only happen after the lock is released.
|
// ref, which can only happen after the lock is released.
|
||||||
if self.inner().weak.fetch_sub(1, Release) == 1 {
|
if self.inner().weak.fetch_sub(1, Release) == 1 {
|
||||||
atomic::fence(Acquire);
|
atomic::fence(Acquire);
|
||||||
unsafe { deallocate(ptr as *mut u8, size_of_val(&*ptr), align_of_val(&*ptr)) }
|
unsafe {
|
||||||
|
deallocate(ptr as *mut u8,
|
||||||
|
size_of_val(&*ptr),
|
||||||
|
align_of_val(&*ptr))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,8 +34,12 @@ extern {
|
|||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn check_size_and_alignment(size: usize, align: usize) {
|
fn check_size_and_alignment(size: usize, align: usize) {
|
||||||
debug_assert!(size != 0);
|
debug_assert!(size != 0);
|
||||||
debug_assert!(size <= isize::MAX as usize, "Tried to allocate too much: {} bytes", size);
|
debug_assert!(size <= isize::MAX as usize,
|
||||||
debug_assert!(usize::is_power_of_two(align), "Invalid alignment of allocation: {}", align);
|
"Tried to allocate too much: {} bytes",
|
||||||
|
size);
|
||||||
|
debug_assert!(usize::is_power_of_two(align),
|
||||||
|
"Invalid alignment of allocation: {}",
|
||||||
|
align);
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: #13996: mark the `allocate` and `reallocate` return value as `noalias`
|
// FIXME: #13996: mark the `allocate` and `reallocate` return value as `noalias`
|
||||||
|
@ -274,7 +274,10 @@ impl<T> RawVec<T> {
|
|||||||
let ptr = if self.cap == 0 {
|
let ptr = if self.cap == 0 {
|
||||||
heap::allocate(new_alloc_size, align)
|
heap::allocate(new_alloc_size, align)
|
||||||
} else {
|
} else {
|
||||||
heap::reallocate(self.ptr() as *mut _, self.cap * elem_size, new_alloc_size, align)
|
heap::reallocate(self.ptr() as *mut _,
|
||||||
|
self.cap * elem_size,
|
||||||
|
new_alloc_size,
|
||||||
|
align)
|
||||||
};
|
};
|
||||||
|
|
||||||
// If allocate or reallocate fail, we'll get `null` back
|
// If allocate or reallocate fail, we'll get `null` back
|
||||||
@ -358,7 +361,10 @@ impl<T> RawVec<T> {
|
|||||||
let ptr = if self.cap == 0 {
|
let ptr = if self.cap == 0 {
|
||||||
heap::allocate(new_alloc_size, align)
|
heap::allocate(new_alloc_size, align)
|
||||||
} else {
|
} else {
|
||||||
heap::reallocate(self.ptr() as *mut _, self.cap * elem_size, new_alloc_size, align)
|
heap::reallocate(self.ptr() as *mut _,
|
||||||
|
self.cap * elem_size,
|
||||||
|
new_alloc_size,
|
||||||
|
align)
|
||||||
};
|
};
|
||||||
|
|
||||||
// If allocate or reallocate fail, we'll get `null` back
|
// If allocate or reallocate fail, we'll get `null` back
|
||||||
@ -392,7 +398,8 @@ impl<T> RawVec<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// This check is my waterloo; it's the only thing Vec wouldn't have to do.
|
// This check is my waterloo; it's the only thing Vec wouldn't have to do.
|
||||||
assert!(self.cap >= amount, "Tried to shrink to a larger capacity");
|
assert!(self.cap >= amount,
|
||||||
|
"Tried to shrink to a larger capacity");
|
||||||
|
|
||||||
if amount == 0 {
|
if amount == 0 {
|
||||||
mem::replace(self, RawVec::new());
|
mem::replace(self, RawVec::new());
|
||||||
@ -466,6 +473,7 @@ impl<T> Drop for RawVec<T> {
|
|||||||
#[inline]
|
#[inline]
|
||||||
fn alloc_guard(alloc_size: usize) {
|
fn alloc_guard(alloc_size: usize) {
|
||||||
if core::usize::BITS < 64 {
|
if core::usize::BITS < 64 {
|
||||||
assert!(alloc_size <= ::core::isize::MAX as usize, "capacity overflow");
|
assert!(alloc_size <= ::core::isize::MAX as usize,
|
||||||
|
"capacity overflow");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -466,7 +466,9 @@ impl<T: ?Sized> Drop for Rc<T> {
|
|||||||
self.dec_weak();
|
self.dec_weak();
|
||||||
|
|
||||||
if self.weak() == 0 {
|
if self.weak() == 0 {
|
||||||
deallocate(ptr as *mut u8, size_of_val(&*ptr), align_of_val(&*ptr))
|
deallocate(ptr as *mut u8,
|
||||||
|
size_of_val(&*ptr),
|
||||||
|
align_of_val(&*ptr))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -785,7 +787,9 @@ impl<T: ?Sized> Drop for Weak<T> {
|
|||||||
// the weak count starts at 1, and will only go to zero if all
|
// the weak count starts at 1, and will only go to zero if all
|
||||||
// the strong pointers have disappeared.
|
// the strong pointers have disappeared.
|
||||||
if self.weak() == 0 {
|
if self.weak() == 0 {
|
||||||
deallocate(ptr as *mut u8, size_of_val(&*ptr), align_of_val(&*ptr))
|
deallocate(ptr as *mut u8,
|
||||||
|
size_of_val(&*ptr),
|
||||||
|
align_of_val(&*ptr))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user