Skip to content

Commit 65bce06

Browse files
bors[bot]phimuemue
andauthored
Merge #415
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>
2 parents b22f6a9 + 9e27154 commit 65bce06

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

src/combinations.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ impl<I> Iterator for Combinations<I>
5151
{
5252
type Item = Vec<I::Item>;
5353
fn next(&mut self) -> Option<Self::Item> {
54-
let mut pool_len = self.pool.len();
55-
5654
if self.first {
5755
if self.pool.is_done() {
5856
return None;
@@ -65,13 +63,11 @@ impl<I> Iterator for Combinations<I>
6563
let mut i: usize = self.indices.len() - 1;
6664

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

74-
while self.indices[i] == i + pool_len - self.indices.len() {
70+
while self.indices[i] == i + self.pool.len() - self.indices.len() {
7571
if i > 0 {
7672
i -= 1;
7773
} else {

0 commit comments

Comments
 (0)