fix Value<T>, take 2
This commit is contained in:
parent
ebec679875
commit
c3804c8930
|
@ -216,12 +216,11 @@ mod job {
|
|||
|
||||
// SAFETY: we know the box is allocated if state was `Pending`.
|
||||
if inline {
|
||||
let mut this = Self(MaybeUninit::uninit());
|
||||
let this = MaybeUninit::new(Self(MaybeUninit::uninit()));
|
||||
unsafe {
|
||||
*mem::transmute::<&mut MaybeUninit<Box<MaybeUninit<T>>>, &mut T>(&mut this.0) =
|
||||
value;
|
||||
this.as_ptr().cast::<T>().cast_mut().write(value);
|
||||
this.assume_init()
|
||||
}
|
||||
this
|
||||
} else {
|
||||
Self(MaybeUninit::new(Box::new(MaybeUninit::new(value))))
|
||||
}
|
||||
|
@ -230,10 +229,8 @@ mod job {
|
|||
|
||||
impl<T> Drop for Value<T> {
|
||||
fn drop(&mut self) {
|
||||
unsafe {
|
||||
// drop contained value.
|
||||
_ = self.get_unchecked(Self::is_inline());
|
||||
}
|
||||
drop(unsafe { self.get_unchecked(Self::is_inline()) });
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -500,13 +497,16 @@ mod job {
|
|||
}
|
||||
|
||||
/// assumes job is in joblist
|
||||
pub unsafe fn unlink(&self) -> Option<()> {
|
||||
pub unsafe fn unlink(&self) {
|
||||
unsafe {
|
||||
let link = self.link_mut();
|
||||
link.prev?.as_ref().link_mut().next = link.next;
|
||||
link.next?.as_ref().link_mut().prev = link.prev;
|
||||
let link = *self.link_mut();
|
||||
if let Some(prev) = link.prev {
|
||||
prev.as_ref().link_mut().next = link.next;
|
||||
}
|
||||
if let Some(next) = link.next {
|
||||
next.as_ref().link_mut().prev = link.prev;
|
||||
}
|
||||
}
|
||||
Some(())
|
||||
}
|
||||
|
||||
pub fn state(&self) -> u8 {
|
||||
|
|
Loading…
Reference in a new issue