Skip to content

Commit a49ccee

Browse files
committed
MutableIter impl for Option + use it in treemap
1 parent c3fe0b9 commit a49ccee

File tree

2 files changed

+13
-15
lines changed

2 files changed

+13
-15
lines changed

src/libcore/option.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ use ops::Add;
4646
use kinds::Copy;
4747
use util;
4848
use num::Zero;
49-
use iter::BaseIter;
49+
use iter::{BaseIter, MutableIter};
5050

5151
#[cfg(test)] use ptr;
5252
#[cfg(test)] use str;
@@ -323,6 +323,13 @@ impl<T> BaseIter<T> for Option<T> {
323323
}
324324
}
325325
326+
impl<T> MutableIter<T> for Option<T> {
327+
#[inline(always)]
328+
fn each_mut(&mut self, f: &fn(&'self mut T) -> bool) {
329+
match *self { None => (), Some(ref mut t) => { f(t); } }
330+
}
331+
}
332+
326333
pub impl<T> Option<T> {
327334
/// Returns true if the option equals `none`
328335
#[inline(always)]

src/libstd/treemap.rs

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ pure fn lt<K: Ord + TotalOrd, V>(a: &TreeMap<K, V>,
7272
}
7373
};
7474

75-
return a_len < b_len;
75+
a_len < b_len
7676
}
7777

7878
impl<K: Ord + TotalOrd, V> Ord for TreeMap<K, V> {
@@ -694,22 +694,13 @@ fn remove<K: TotalOrd, V>(node: &mut Option<~TreeNode<K, V>>,
694694

695695
skew(save);
696696

697-
match save.right {
698-
Some(ref mut right) => {
697+
for save.right.each_mut |right| {
699698
skew(right);
700-
match right.right {
701-
Some(ref mut x) => { skew(x) },
702-
None => ()
703-
}
704-
}
705-
None => ()
699+
for right.right.each_mut |x| { skew(x) }
706700
}
707701

708702
split(save);
709-
match save.right {
710-
Some(ref mut x) => { split(x) },
711-
None => ()
712-
}
703+
for save.right.each_mut |x| { split(x) }
713704
}
714705

715706
return removed;
@@ -718,7 +709,7 @@ fn remove<K: TotalOrd, V>(node: &mut Option<~TreeNode<K, V>>,
718709
}
719710

720711
*node = None;
721-
return true;
712+
true
722713
}
723714

724715
#[cfg(test)]

0 commit comments

Comments
 (0)