Skip to content

Commit

Permalink
Manually fuse the inner iterator in FlattenCompat
Browse files Browse the repository at this point in the history
  • Loading branch information
SkiFire13 committed Jan 23, 2021
1 parent f241c10 commit 5aa625b
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions library/core/src/iter/adapters/flatten.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,13 @@ where
}
}
match self.iter.next() {
None => return self.backiter.as_mut()?.next(),
None => match self.backiter.as_mut()?.next() {
None => {
self.backiter = None;
return None;
}
elt @ Some(_) => return elt,
},
Some(inner) => self.frontiter = Some(inner.into_iter()),
}
}
Expand Down Expand Up @@ -353,7 +359,13 @@ where
}
}
match self.iter.next_back() {
None => return self.frontiter.as_mut()?.next_back(),
None => match self.frontiter.as_mut()?.next_back() {
None => {
self.frontiter = None;
return None;
}
elt @ Some(_) => return elt,
},
next => self.backiter = next.map(IntoIterator::into_iter),
}
}
Expand Down

0 comments on commit 5aa625b

Please sign in to comment.