orium / rpds

Rust persistent data structures
Mozilla Public License 2.0
1.22k stars 57 forks source link

Avoiding stackoverflow when dropping large List #46

Closed lulitao1997 closed 5 years ago

lulitao1997 commented 5 years ago

As #41 suggests, when dropping a large List, rust recursively calls Arc's drop function, which leads to stackoverflow. We can implement our custom Drop trait for List to prevent this, the following code seems to solve this problem:

impl<T, P> Drop for List<T, P>
where
    P: SharedPointerKind,
{
    fn drop(&mut self) {
        let mut head = self.head.take();
        while let Some(node) = head {
            if let Ok(mut node) = SharedPointer::try_unwrap(node) {
                head = node.next.take();
            }
            else {
                break;
            }
        }
    }
}
lulitao1997 commented 5 years ago

can i make a pull request for this? :)

orium commented 5 years ago

Hi @lulitao1997. A PR will be more than welcome :)

orium commented 5 years ago

Fixed by #47