Skip to content

Commit

Permalink
Reduce callsites in Chain::count()
Browse files Browse the repository at this point in the history
  • Loading branch information
cuviper committed Apr 7, 2020
1 parent 859b8da commit 8aac107
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/libcore/iter/adapters/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,15 @@ where
#[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
Expand Down

0 comments on commit 8aac107

Please sign in to comment.