Skip to content

Commit

Permalink
improve add() function
Browse files Browse the repository at this point in the history
  • Loading branch information
Congyuwang committed Feb 18, 2024
1 parent 0f4594f commit 5ba71ed
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,13 @@ impl<T> ListHead<T> {
/// is still complete.
#[inline(always)]
unsafe fn add(&mut self, other: &mut ListHead<T>) {
let next = self.next.assume_init_mut().as_mut();
let other_ptr = other.ptr();

other.prev.write(self.ptr());
other.next = self.next;

let next = self.next.assume_init_mut().as_mut();
next.prev.write(other.ptr());
self.next.write(other.ptr());
next.prev.write(other_ptr);
self.next.write(other_ptr);
}

#[inline(always)]
Expand Down

0 comments on commit 5ba71ed

Please sign in to comment.