]> git.lizzy.rs Git - rust.git/commitdiff
Reduce callsites in Chain::count()
authorJosh Stone <jistone@redhat.com>
Tue, 7 Apr 2020 23:50:16 +0000 (16:50 -0700)
committerJosh Stone <jistone@redhat.com>
Tue, 7 Apr 2020 23:50:16 +0000 (16:50 -0700)
src/libcore/iter/adapters/chain.rs

index 6c97c43df407ac4dfdff08fe2f131782c63bc65d..0100e62fae655da287f4a704bbdd4c9e49acabbd 100644 (file)
@@ -62,12 +62,15 @@ fn next(&mut self) -> Option<A::Item> {
     #[inline]
     #[rustc_inherit_overflow_checks]
     fn count(self) -> usize {
-        match self {
-            Chain { a: Some(a), b: Some(b) } => a.count() + b.count(),
-            Chain { a: Some(a), b: None } => a.count(),
-            Chain { a: None, b: Some(b) } => b.count(),
-            Chain { a: None, b: None } => 0,
-        }
+        let a_count = match self.a {
+            Some(a) => a.count(),
+            None => 0,
+        };
+        let b_count = match self.b {
+            Some(b) => b.count(),
+            None => 0,
+        };
+        a_count + b_count
     }
 
     fn try_fold<Acc, F, R>(&mut self, mut acc: Acc, mut f: F) -> R