Skip to content

Commit 7a6e436

Browse files
author
blake2-ppc
committed
---
yaml --- r: 64211 b: refs/heads/snap-stage3 c: 8d06efb h: refs/heads/master i: 64209: 1f77e09 64207: 63c2753 v: v3
1 parent 0d87259 commit 7a6e436

File tree

2 files changed

+16
-18
lines changed

2 files changed

+16
-18
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 2d28d645422c1617be58c8ca7ad9a457264ca850
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 7b1c57713d331266d632c4fa11d4cdfaaa895ac7
4+
refs/heads/snap-stage3: 8d06efb8ea0857844f856ab5fd87aed89d4bf718
55
refs/heads/try: 7b78b52e602bb3ea8174f9b2006bff3315f03ef9
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/libextra/dlist.rs

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@ impl<T> Rawlink<T> {
9898
}
9999
}
100100

101+
/// Set the .prev field on `next`, then return `Some(next)`
102+
fn link_with_prev<T>(mut next: ~Node<T>, prev: Rawlink<Node<T>>) -> Link<T> {
103+
next.prev = prev;
104+
Some(next)
105+
}
106+
101107
impl<T> Container for List<T> {
102108
/// O(1)
103109
fn is_empty(&self) -> bool {
@@ -216,20 +222,17 @@ impl<T> List<T> {
216222
///
217223
/// O(1)
218224
pub fn pop_front(&mut self) -> Option<T> {
219-
match self.list_head {
225+
match util::replace(&mut self.list_head, None) {
220226
None => None,
221-
ref mut head @ Some(*) => {
227+
Some(old_head) => {
222228
self.length -= 1;
223-
match *head.swap_unwrap() {
229+
match *old_head {
224230
Node{value: value, next: Some(next), prev: _} => {
225-
let mut mnext = next;
226-
mnext.prev = Rawlink::none();
227-
*head = Some(mnext);
231+
self.list_head = link_with_prev(next, Rawlink::none());
228232
Some(value)
229233
}
230234
Node{value: value, next: None, prev: _} => {
231235
self.list_tail = Rawlink::none();
232-
*head = None;
233236
Some(value)
234237
}
235238
}
@@ -247,9 +250,7 @@ impl<T> List<T> {
247250
match other {
248251
List{list_head: None, list_tail: _, length: _} => return,
249252
List{list_head: Some(node), list_tail: o_tail, length: o_length} => {
250-
let mut lnk_node = node;
251-
lnk_node.prev = self.list_tail;
252-
tail.next = Some(lnk_node);
253+
tail.next = link_with_prev(node, self.list_tail);
253254
self.list_tail = o_tail;
254255
self.length += o_length;
255256
}
@@ -447,13 +448,10 @@ impl<'self, A> ListInsertCursor<A> for MutForwardIterator<'self, A> {
447448
None => return self.list.push_front(elt), // at head
448449
Some(prev) => prev,
449450
};
450-
let mut node_own = prev_node.next.swap_unwrap();
451-
let mut ins_node = ~Node{value: elt,
452-
next: None,
453-
prev: Rawlink::some(prev_node)};
454-
node_own.prev = Rawlink::some(ins_node);
455-
ins_node.next = Some(node_own);
456-
prev_node.next = Some(ins_node);
451+
let mut ins_node = ~Node{value: elt, next: None, prev: Rawlink::none()};
452+
let node_own = prev_node.next.swap_unwrap();
453+
ins_node.next = link_with_prev(node_own, Rawlink::some(ins_node));
454+
prev_node.next = link_with_prev(ins_node, Rawlink::some(prev_node));
457455
self.list.length += 1;
458456
}
459457
}

0 commit comments

Comments
 (0)