Skip to content

Commit 140a6a4

Browse files
committed
refactor(filter): Flatten some logic
1 parent 50bde7d commit 140a6a4

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

crates/snapbox/src/filter/pattern.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -492,29 +492,29 @@ fn normalize_str_to_redactions(input: &str, pattern: &str, redactions: &Redactio
492492
let mut input_index = 0;
493493
let input_lines: Vec<_> = crate::utils::LinesWithTerminator::new(input).collect();
494494
let mut pattern_lines = crate::utils::LinesWithTerminator::new(pattern).peekable();
495-
'outer: while let Some(pattern_line) = pattern_lines.next() {
495+
while let Some(pattern_line) = pattern_lines.next() {
496496
if is_line_elide(pattern_line) {
497497
let Some(next_pattern_line) = pattern_lines.peek() else {
498-
// Give up doing further normalization
498+
// Stop as elide consumes to end
499499
normalized.push(pattern_line);
500-
// captured rest so don't copy remaining lines over
501500
input_index = input_lines.len();
502501
break;
503502
};
504-
for (index_offset, next_input_line) in
505-
input_lines[input_index..].iter().copied().enumerate()
506-
{
507-
if line_matches(next_input_line, next_pattern_line, redactions) {
508-
normalized.push(pattern_line);
509-
input_index += index_offset;
510-
continue 'outer;
511-
}
512-
}
513-
// Give up doing further normalization
514-
break;
503+
let Some(index_offset) =
504+
input_lines[input_index..]
505+
.iter()
506+
.position(|next_input_line| {
507+
line_matches(next_input_line, next_pattern_line, redactions)
508+
})
509+
else {
510+
// Give up as we can't find where the elide ends
511+
break;
512+
};
513+
normalized.push(pattern_line);
514+
input_index += index_offset;
515515
} else {
516516
let Some(input_line) = input_lines.get(input_index) else {
517-
// Give up doing further normalization
517+
// Give up as we have no more content to check
518518
break;
519519
};
520520

0 commit comments

Comments
 (0)