Skip to content

Commit b4ac4a5

Browse files
committed
Removing the outer loop on the iterator for the zip_nested_vectors
function - breaking from the inner loop was an unnecessary addition
1 parent d099e66 commit b4ac4a5

File tree

1 file changed

+16
-20
lines changed

1 file changed

+16
-20
lines changed

lightning-invoice/src/utils.rs

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -287,27 +287,23 @@ fn zip_nested_vectors<T: Clone>(vecs: Vec<Vec<T>>, result_size: usize) -> impl I
287287
let mut total_hints_returned = 0;
288288

289289
core::iter::from_fn(move || loop {
290-
let return_value = loop {
291-
if total_hints_returned == result_size || hint_index == max_vector_length {
292-
break None;
293-
};
294-
let hint_value =
295-
if vecs[vector_index].len() != 0 && vecs[vector_index].len() > hint_index {
296-
Some(vecs[vector_index][hint_index].clone())
297-
} else {
298-
None // no value retrieved - continue looping
299-
};
300-
vector_index += 1;
301-
if hint_index < max_vector_length && vector_index == number_inner_vectors {
302-
vector_index = 0;
303-
hint_index += 1;
304-
};
305-
if !hint_value.is_none() {
306-
total_hints_returned += 1;
307-
break hint_value;
308-
};
290+
if total_hints_returned == result_size || hint_index == max_vector_length {
291+
return None;
292+
};
293+
let hint_value = if vecs[vector_index].len() != 0 && vecs[vector_index].len() > hint_index {
294+
Some(vecs[vector_index][hint_index].clone())
295+
} else {
296+
None // no value retrieved - continue looping
297+
};
298+
vector_index += 1;
299+
if hint_index < max_vector_length && vector_index == number_inner_vectors {
300+
vector_index = 0;
301+
hint_index += 1;
302+
};
303+
if !hint_value.is_none() {
304+
total_hints_returned += 1;
305+
return hint_value;
309306
};
310-
return return_value;
311307
})
312308
}
313309

0 commit comments

Comments
 (0)