From 8aac1077ed495ef8d1241ce76d4b64d7eb13a856 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Tue, 7 Apr 2020 16:50:16 -0700 Subject: [PATCH] Reduce callsites in Chain::count() --- src/libcore/iter/adapters/chain.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/libcore/iter/adapters/chain.rs b/src/libcore/iter/adapters/chain.rs index 6c97c43df40..0100e62fae6 100644 --- a/src/libcore/iter/adapters/chain.rs +++ b/src/libcore/iter/adapters/chain.rs @@ -62,12 +62,15 @@ fn next(&mut self) -> Option { #[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(&mut self, mut acc: Acc, mut f: F) -> R