diff: omit insertion of terminal range that would be compacted

This isn't important, but I'm going to add another empty range at the start,
and it's easier if the modification of regions is scoped.
This commit is contained in:
Yuya Nishihara 2024-10-12 11:50:01 +09:00
parent ff0a1ad075
commit 1967a55b92

View file

@ -586,7 +586,7 @@ impl<'input> Diff<'input> {
let other_sources = iter::zip(&other_inputs, other_token_ranges)
.map(|(input, token_ranges)| DiffSource::new(input, token_ranges))
.collect_vec();
let mut unchanged_regions = match &*other_sources {
let unchanged_regions = match &*other_sources {
// Consider the whole range of the base input as unchanged compared
// to itself.
[] => {
@ -606,7 +606,7 @@ impl<'input> Diff<'input> {
first_other_source,
&comp,
);
if tail_other_sources.is_empty() {
let mut unchanged_regions: Vec<_> = if tail_other_sources.is_empty() {
first_positions
.iter()
.map(|&(base_pos, other_pos)| {
@ -647,8 +647,6 @@ impl<'input> Diff<'input> {
)
})
.collect()
}
}
};
// Add an empty range at the end to make life easier for hunks().
unchanged_regions.push(UnchangedRange {
@ -658,6 +656,9 @@ impl<'input> Diff<'input> {
.map(|input| input.len()..input.len())
.collect(),
});
unchanged_regions
}
};
let mut diff = Self {
base_input,