From c92f6a5ad7ed58b48832bd49a38111e385bdf598 Mon Sep 17 00:00:00 2001 From: philipp Date: Thu, 6 Feb 2020 23:52:52 +0100 Subject: [PATCH 1/2] Avoid redundant bookkeeping in `pool_len` lazy_buffer gives `len` in via a field lookup (Vec::len), so I do not see why we should duplicate this compuation manually. --- src/combinations.rs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/combinations.rs b/src/combinations.rs index e8efb473f..291b326b9 100644 --- a/src/combinations.rs +++ b/src/combinations.rs @@ -51,8 +51,6 @@ impl Iterator for Combinations { type Item = Vec; fn next(&mut self) -> Option { - let mut pool_len = self.pool.len(); - if self.first { if self.pool.is_done() { return None; @@ -65,13 +63,11 @@ impl Iterator for Combinations 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.is_done() { + 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 { From 9e2715416ae52959447bec3f8b453023b1699a4e Mon Sep 17 00:00:00 2001 From: philipp Date: Tue, 11 Feb 2020 22:27:21 +0100 Subject: [PATCH 2/2] Avoid redundant call to is_done get_next does the same check internally. --- src/combinations.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/combinations.rs b/src/combinations.rs index 291b326b9..875951808 100644 --- a/src/combinations.rs +++ b/src/combinations.rs @@ -63,7 +63,7 @@ impl Iterator for Combinations let mut i: usize = self.indices.len() - 1; // Check if we need to consume more from the iterator - if self.indices[i] == self.pool.len() - 1 && !self.pool.is_done() { + if self.indices[i] == self.pool.len() - 1 { self.pool.get_next(); // may change pool size }