Skip to content

Commit 50b29d9

Browse files
author
Ulrik Sverdrup
committed
---
yaml --- r: 212253 b: refs/heads/tmp c: 32037a5 h: refs/heads/master i: 212251: 3995786 v: v3
1 parent 08179dd commit 50b29d9

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
@@ -32,7 +32,7 @@ refs/heads/building: 126db549b038c84269a1e4fe46f051b2c15d6970
3232
refs/heads/beta: 62e70d35be3fe532c26a400b499c58a18f18dd3a
3333
refs/heads/windistfix: 7608dbad651f02e837ed05eef3d74a6662a6e928
3434
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
35-
refs/heads/tmp: 16cefab795d37c289fe3df2e824fdf65307c6c58
35+
refs/heads/tmp: 32037a5696272f1c34f3692dcdc59b4ada91bdc7
3636
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f
3737
refs/tags/homu-tmp: b77d60adb019bb5de05e884a99f3290ec4694137
3838
refs/heads/gate: 97c84447b65164731087ea82685580cc81424412

branches/tmp/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)