mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-25 11:35:05 +08:00
Remove the useless Manually drop
This commit is contained in:
parent
0409a26cd8
commit
a7a01646cf
@ -1,6 +1,5 @@
|
|||||||
use std::fmt;
|
|
||||||
use std::mem::{self, ManuallyDrop};
|
|
||||||
use std::sync::atomic::AtomicPtr;
|
use std::sync::atomic::AtomicPtr;
|
||||||
|
use std::{fmt, mem};
|
||||||
|
|
||||||
/// An append-only linked-list that returns a mutable references to the pushed items.
|
/// An append-only linked-list that returns a mutable references to the pushed items.
|
||||||
pub struct AppendOnlyLinkedList<T> {
|
pub struct AppendOnlyLinkedList<T> {
|
||||||
@ -8,7 +7,7 @@ pub struct AppendOnlyLinkedList<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct Node<T> {
|
struct Node<T> {
|
||||||
item: ManuallyDrop<T>,
|
item: T,
|
||||||
parent: AtomicPtr<Node<T>>,
|
parent: AtomicPtr<Node<T>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -23,10 +22,7 @@ impl<T> AppendOnlyLinkedList<T> {
|
|||||||
pub fn push(&self, item: T) -> &mut T {
|
pub fn push(&self, item: T) -> &mut T {
|
||||||
use std::sync::atomic::Ordering::{Relaxed, SeqCst};
|
use std::sync::atomic::Ordering::{Relaxed, SeqCst};
|
||||||
|
|
||||||
let node = Box::leak(Box::new(Node {
|
let node = Box::leak(Box::new(Node { item, parent: AtomicPtr::default() }));
|
||||||
item: ManuallyDrop::new(item),
|
|
||||||
parent: AtomicPtr::default(),
|
|
||||||
}));
|
|
||||||
|
|
||||||
let mut head = self.head.load(SeqCst);
|
let mut head = self.head.load(SeqCst);
|
||||||
loop {
|
loop {
|
||||||
@ -82,13 +78,10 @@ impl<T> Iterator for IntoIter<T> {
|
|||||||
if ptr.is_null() {
|
if ptr.is_null() {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
let mut node = unsafe { Box::from_raw(ptr) };
|
let node = unsafe { Box::from_raw(ptr) };
|
||||||
// Let's set the next node to read to be the parent of this one
|
// Let's set the next node to read to be the parent of this one
|
||||||
self.0 = node.parent;
|
self.0 = node.parent;
|
||||||
// ...and take the item from the Node before it is dropped
|
Some(node.item)
|
||||||
let item = unsafe { ManuallyDrop::take(&mut node.item) };
|
|
||||||
Some(item)
|
|
||||||
// ...then drop the Node itself
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -100,9 +93,6 @@ impl<T> Drop for IntoIter<T> {
|
|||||||
let mut node = unsafe { Box::from_raw(ptr) };
|
let mut node = unsafe { Box::from_raw(ptr) };
|
||||||
// Let's set the next node to read to be the parent of this one
|
// Let's set the next node to read to be the parent of this one
|
||||||
ptr = *node.parent.get_mut();
|
ptr = *node.parent.get_mut();
|
||||||
// ...and drop the item ourselves.
|
|
||||||
unsafe { ManuallyDrop::drop(&mut node.item) }
|
|
||||||
// ...then drop the Node itself
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user