Skip to content

Commit

Permalink
Merge #415
Browse files Browse the repository at this point in the history
415: Simplify `Combinations::next` r=jswrenn a=phimuemue

* `pool.len` looks up the length of a vector, ([which is just a field lookup](https://doc.rust-lang.org/src/alloc/vec.rs.html#1335-1337)), so I see no real value in manually doing the same computation.

* Checking `pool.is_done` before calling `pool.get_next` is redundant, as `get_next` does the same check internally.

Co-authored-by: philipp <descpl@yahoo.de>
  • Loading branch information
bors[bot] and phimuemue committed Feb 29, 2020
2 parents b22f6a9 + 9e27154 commit 65bce06
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions src/combinations.rs
Expand Up @@ -51,8 +51,6 @@ impl<I> Iterator for Combinations<I>
{
type Item = Vec<I::Item>;
fn next(&mut self) -> Option<Self::Item> {
let mut pool_len = self.pool.len();

if self.first {
if self.pool.is_done() {
return None;
Expand All @@ -65,13 +63,11 @@ impl<I> Iterator for Combinations<I>
let mut i: usize = self.indices.len() - 1;

// Check if we need to consume more from the iterator
if self.indices[i] == pool_len - 1 && !self.pool.is_done() {
if self.pool.get_next() {
pool_len += 1;
}
if self.indices[i] == self.pool.len() - 1 {
self.pool.get_next(); // may change pool size
}

while self.indices[i] == i + pool_len - self.indices.len() {
while self.indices[i] == i + self.pool.len() - self.indices.len() {
if i > 0 {
i -= 1;
} else {
Expand Down

0 comments on commit 65bce06

Please sign in to comment.