Skip to content

Commit 8aac107

Browse files
committed
Reduce callsites in Chain::count()
1 parent 859b8da commit 8aac107

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/libcore/iter/adapters/chain.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,15 @@ where
6262
#[inline]
6363
#[rustc_inherit_overflow_checks]
6464
fn count(self) -> usize {
65-
match self {
66-
Chain { a: Some(a), b: Some(b) } => a.count() + b.count(),
67-
Chain { a: Some(a), b: None } => a.count(),
68-
Chain { a: None, b: Some(b) } => b.count(),
69-
Chain { a: None, b: None } => 0,
70-
}
65+
let a_count = match self.a {
66+
Some(a) => a.count(),
67+
None => 0,
68+
};
69+
let b_count = match self.b {
70+
Some(b) => b.count(),
71+
None => 0,
72+
};
73+
a_count + b_count
7174
}
7275

7376
fn try_fold<Acc, F, R>(&mut self, mut acc: Acc, mut f: F) -> R

0 commit comments

Comments
 (0)