Skip to content

Commit b458fc2

Browse files
committed
Cleaning up the loop naming in rotate_nested_vectors
1 parent d4d8b81 commit b458fc2

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

lightning-invoice/src/utils.rs

+5-8
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,6 @@ where
276276
});
277277

278278
phantom_hints.push(route_hints);
279-
280279
}
281280

282281
// We have one vector per real node involved in creating the phantom invoice. To distribute
@@ -289,19 +288,18 @@ where
289288
/// Draw items iteratively from multiple nested vectors. The items are retrieved by index and
290289
/// rotates through the vectors - first the zero index then the first index then second index, etc.
291290
fn rotate_nested_vectors<T, I: Iterator<Item = T>>(mut vecs: Vec<I>) -> impl Iterator<Item = T> {
292-
let mut idx = 0;
291+
let mut iterations = 0;
293292

294293
core::iter::from_fn(move || {
295294
let mut exhausted_vectors = 0;
296295
loop {
297296
if vecs.is_empty() {
298297
return None;
299298
}
300-
let next_idx = idx % vecs.len();
301-
let hint_opt = vecs[next_idx].next();
302-
idx += 1;
303-
if let Some(hint) = hint_opt {
304-
return Some(hint);
299+
let next_idx = iterations % vecs.len();
300+
iterations += 1;
301+
if let Some(item) = vecs[next_idx].next() {
302+
return Some(item);
305303
}
306304
// exhausted_vectors increase when the "next_idx" vector is exhausted
307305
exhausted_vectors += 1;
@@ -1915,7 +1913,6 @@ mod test {
19151913
}
19161914
}
19171915

1918-
19191916
#[test]
19201917
fn test_zip_nested_vectors() {
19211918
// two nested vectors

0 commit comments

Comments
 (0)