Skip to content

Commit f3d436f

Browse files
author
Ulrik Sverdrup
committed
---
yaml --- r: 218999 b: refs/heads/snap-stage3 c: 32037a5 h: refs/heads/master i: 218997: dea205a 218995: e6ba550 218991: fc80913 v: v3
1 parent 588f3be commit f3d436f

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
refs/heads/master: c044791d80ea0dc5c4b57b6030a67b69f8510239
3-
refs/heads/snap-stage3: 16cefab795d37c289fe3df2e824fdf65307c6c58
3+
refs/heads/snap-stage3: 32037a5696272f1c34f3692dcdc59b4ada91bdc7
44
refs/heads/try: b53c0f93eedcdedd4fd89bccc5a3a09d1c5cd23e
55
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
66
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596

branches/snap-stage3/src/libcollections/linked_list.rs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,15 @@ impl<T> Rawlink<T> {
129129
}
130130
}
131131

132+
impl<'a, T> From<&'a mut Link<T>> for Rawlink<Node<T>> {
133+
fn from(node: &'a mut Link<T>) -> Self {
134+
match node.as_mut() {
135+
None => Rawlink::none(),
136+
Some(ptr) => Rawlink::some(ptr),
137+
}
138+
}
139+
}
140+
132141
impl<T> Clone for Rawlink<T> {
133142
#[inline]
134143
fn clone(&self) -> Rawlink<T> {
@@ -165,8 +174,8 @@ impl<T> LinkedList<T> {
165174
fn push_front_node(&mut self, mut new_head: Box<Node<T>>) {
166175
match self.list_head {
167176
None => {
168-
self.list_tail = Rawlink::some(&mut *new_head);
169177
self.list_head = link_no_prev(new_head);
178+
self.list_tail = Rawlink::from(&mut self.list_head);
170179
}
171180
Some(ref mut head) => {
172181
new_head.prev = Rawlink::none();
@@ -197,8 +206,8 @@ impl<T> LinkedList<T> {
197206
match unsafe { self.list_tail.resolve_mut() } {
198207
None => return self.push_front_node(new_tail),
199208
Some(tail) => {
200-
self.list_tail = Rawlink::some(&mut *new_tail);
201209
tail.set_next(new_tail);
210+
self.list_tail = Rawlink::from(&mut tail.next);
202211
}
203212
}
204213
self.length += 1;
@@ -297,13 +306,9 @@ impl<T> LinkedList<T> {
297306
#[inline]
298307
#[stable(feature = "rust1", since = "1.0.0")]
299308
pub fn iter_mut(&mut self) -> IterMut<T> {
300-
let head_raw = match self.list_head {
301-
Some(ref mut h) => Rawlink::some(&mut **h),
302-
None => Rawlink::none(),
303-
};
304-
IterMut{
309+
IterMut {
305310
nelem: self.len(),
306-
head: head_raw,
311+
head: Rawlink::from(&mut self.list_head),
307312
tail: self.list_tail,
308313
list: self
309314
}
@@ -717,10 +722,7 @@ impl<'a, A> Iterator for IterMut<'a, A> {
717722
unsafe {
718723
self.head.resolve_mut().map(|next| {
719724
self.nelem -= 1;
720-
self.head = match next.next {
721-
Some(ref mut node) => Rawlink::some(&mut **node),
722-
None => Rawlink::none(),
723-
};
725+
self.head = Rawlink::from(&mut next.next);
724726
&mut next.value
725727
})
726728
}

0 commit comments

Comments
 (0)