File tree Expand file tree Collapse file tree 1 file changed +3
-11
lines changed Expand file tree Collapse file tree 1 file changed +3
-11
lines changed Original file line number Diff line number Diff line change @@ -626,21 +626,13 @@ impl<T> LinkedList<T> {
626
626
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
627
627
impl < T > Drop for LinkedList < T > {
628
628
fn drop ( & mut self ) {
629
- // Dissolve the linked_list in backwards direction
629
+ // Dissolve the linked_list in a loop.
630
630
// Just dropping the list_head can lead to stack exhaustion
631
631
// when length is >> 1_000_000
632
- let mut tail = self . list_tail ;
633
- loop {
634
- match tail. resolve ( ) {
635
- None => break ,
636
- Some ( prev) => {
637
- prev. next . take ( ) ; // release Box<Node<T>>
638
- tail = prev. prev ;
639
- }
640
- }
632
+ while let Some ( mut head_) = self . list_head . take ( ) {
633
+ self . list_head = head_. next . take ( ) ;
641
634
}
642
635
self . length = 0 ;
643
- self . list_head = None ;
644
636
self . list_tail = Rawlink :: none ( ) ;
645
637
}
646
638
}
You can’t perform that action at this time.
0 commit comments