diff options
| author | Ulrik Sverdrup <root@localhost> | 2015-06-06 14:26:39 +0200 |
|---|---|---|
| committer | Ulrik Sverdrup <root@localhost> | 2015-06-06 14:26:39 +0200 |
| commit | a090e1f411b65236b5ca8aad3e9375426fcd075e (patch) | |
| tree | 92863e0e61ea21a3eba08a8e7c7ae6176b543b1e /src | |
| parent | da0d45243bbb04ea7efec686162d0b9ce2ec4734 (diff) | |
| download | rust-a090e1f411b65236b5ca8aad3e9375426fcd075e.tar.gz rust-a090e1f411b65236b5ca8aad3e9375426fcd075e.zip | |
linked_list: Use a safe loop in Drop
Diffstat (limited to 'src')
| -rw-r--r-- | src/libcollections/linked_list.rs | 14 |
1 files changed, 3 insertions, 11 deletions
diff --git a/src/libcollections/linked_list.rs b/src/libcollections/linked_list.rs index 0bfbfd73377..b82a25544c9 100644 --- a/src/libcollections/linked_list.rs +++ b/src/libcollections/linked_list.rs @@ -626,21 +626,13 @@ impl<T> LinkedList<T> { #[stable(feature = "rust1", since = "1.0.0")] impl<T> Drop for LinkedList<T> { fn drop(&mut self) { - // Dissolve the linked_list in backwards direction + // Dissolve the linked_list in a loop. // Just dropping the list_head can lead to stack exhaustion // when length is >> 1_000_000 - let mut tail = self.list_tail; - loop { - match tail.resolve() { - None => break, - Some(prev) => { - prev.next.take(); // release Box<Node<T>> - tail = prev.prev; - } - } + while let Some(mut head_) = self.list_head.take() { + self.list_head = head_.next.take(); } self.length = 0; - self.list_head = None; self.list_tail = Rawlink::none(); } } |
