about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-03-14 04:06:31 -0700
committerbors <bors@rust-lang.org>2014-03-14 04:06:31 -0700
commitd367482491ab82af8cc88f2f822fef725237cfbe (patch)
tree88dbc34114ee1c6597c7515790d69728336d1555 /src/libstd
parent29756a3b762881a286f8df13dba00594035d1fc0 (diff)
parent6ff207b415233072bff2efb4b7b0f5fe883348e5 (diff)
downloadrust-d367482491ab82af8cc88f2f822fef725237cfbe.tar.gz
rust-d367482491ab82af8cc88f2f822fef725237cfbe.zip
auto merge of #12871 : aochagavia/rust/Optimize-while_some, r=alexcrichton
The old 'while' needed to match 2 times for each iteration. With the new 'loop' there is just one match needed.

I have also replaced 'blk' by 'f' to be more consistent with parameter names in other functions that are implemented for Option<T>
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/option.rs9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/libstd/option.rs b/src/libstd/option.rs
index 31605ca961e..2a0071526b8 100644
--- a/src/libstd/option.rs
+++ b/src/libstd/option.rs
@@ -295,10 +295,13 @@ impl<T> Option<T> {
 
     /// Applies a function zero or more times until the result is `None`.
     #[inline]
-    pub fn while_some(self, blk: |v: T| -> Option<T>) {
+    pub fn while_some(self, f: |v: T| -> Option<T>) {
         let mut opt = self;
-        while opt.is_some() {
-            opt = blk(opt.unwrap());
+        loop {
+            match opt {
+                Some(x) => opt = f(x),
+                None => break
+            }
         }
     }