Skip to content

Commit

Permalink
Reduce callsites in Chain::last()
Browse files Browse the repository at this point in the history
  • Loading branch information
cuviper committed Apr 7, 2020
1 parent 8aac107 commit 2c4cffd
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions src/libcore/iter/adapters/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,17 +130,16 @@ where

#[inline]
fn last(self) -> Option<A::Item> {
match self {
Chain { a: Some(a), b: Some(b) } => {
// Must exhaust a before b.
let a_last = a.last();
let b_last = b.last();
b_last.or(a_last)
}
Chain { a: Some(a), b: None } => a.last(),
Chain { a: None, b: Some(b) } => b.last(),
Chain { a: None, b: None } => None,
}
// Must exhaust a before b.
let a_last = match self.a {
Some(a) => a.last(),
None => None,
};
let b_last = match self.b {
Some(b) => b.last(),
None => None,
};
b_last.or(a_last)
}

#[inline]
Expand Down

0 comments on commit 2c4cffd

Please sign in to comment.