Skip to content

Commit d8254c3

Browse files
author
Ulrik Sverdrup
committed
---
yaml --- r: 211955 b: refs/heads/auto c: 32037a5 h: refs/heads/master i: 211953: 701477e 211951: 32e2cfe v: v3
1 parent 5dd9812 commit d8254c3

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
@@ -10,7 +10,7 @@ refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1010
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1111
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1212
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
13-
refs/heads/auto: 16cefab795d37c289fe3df2e824fdf65307c6c58
13+
refs/heads/auto: 32037a5696272f1c34f3692dcdc59b4ada91bdc7
1414
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1515
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1616
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336

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