From a49ccee68efc7ec05e882e5929669108f65f74fa Mon Sep 17 00:00:00 2001 From: Daniel Micay Date: Thu, 14 Mar 2013 23:16:15 -0400 Subject: [PATCH] MutableIter impl for Option + use it in treemap --- src/libcore/option.rs | 9 ++++++++- src/libstd/treemap.rs | 19 +++++-------------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/libcore/option.rs b/src/libcore/option.rs index 64135b3b8e156..1e3bba64f2747 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -46,7 +46,7 @@ use ops::Add; use kinds::Copy; use util; use num::Zero; -use iter::BaseIter; +use iter::{BaseIter, MutableIter}; #[cfg(test)] use ptr; #[cfg(test)] use str; @@ -323,6 +323,13 @@ impl BaseIter for Option { } } +impl MutableIter for Option { + #[inline(always)] + fn each_mut(&mut self, f: &fn(&'self mut T) -> bool) { + match *self { None => (), Some(ref mut t) => { f(t); } } + } +} + pub impl Option { /// Returns true if the option equals `none` #[inline(always)] diff --git a/src/libstd/treemap.rs b/src/libstd/treemap.rs index 8d4ff9941950a..e0c60c72ca76a 100644 --- a/src/libstd/treemap.rs +++ b/src/libstd/treemap.rs @@ -72,7 +72,7 @@ pure fn lt(a: &TreeMap, } }; - return a_len < b_len; + a_len < b_len } impl Ord for TreeMap { @@ -694,22 +694,13 @@ fn remove(node: &mut Option<~TreeNode>, skew(save); - match save.right { - Some(ref mut right) => { + for save.right.each_mut |right| { skew(right); - match right.right { - Some(ref mut x) => { skew(x) }, - None => () - } - } - None => () + for right.right.each_mut |x| { skew(x) } } split(save); - match save.right { - Some(ref mut x) => { split(x) }, - None => () - } + for save.right.each_mut |x| { split(x) } } return removed; @@ -718,7 +709,7 @@ fn remove(node: &mut Option<~TreeNode>, } *node = None; - return true; + true } #[cfg(test)]