Skip to content

Commit

Permalink
diff: inline Diff::default_refinement() in diff()
Browse files Browse the repository at this point in the history
There are no callers other than tests and benches.
  • Loading branch information
yuja committed Aug 19, 2024
1 parent 864dd73 commit 6101a66
Showing 1 changed file with 4 additions and 16 deletions.
20 changes: 4 additions & 16 deletions lib/src/diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -505,21 +505,6 @@ impl<'input> Diff<'input> {
diff
}

// TODO: At least when merging, it's wasteful to refine the diff if e.g. if 2
// out of 3 inputs match in the differing regions. Perhaps the refine()
// method should be on the hunk instead (probably returning a new Diff)?
// That would let each user decide which hunks to refine. However, it would
// probably mean that many callers repeat the same code. Perhaps it
// should be possible to refine a whole diff *or* individual hunks.
pub fn default_refinement<T: AsRef<[u8]> + ?Sized + 'input>(
inputs: impl IntoIterator<Item = &'input T>,
) -> Self {
let mut diff = Diff::for_tokenizer(inputs, find_line_ranges);
diff.refine_changed_regions(find_word_ranges);
diff.refine_changed_regions(find_nonword_ranges);
diff
}

pub fn hunks<'diff>(&'diff self) -> DiffHunkIterator<'diff, 'input> {
let previous_offsets = vec![0; self.other_inputs.len()];
DiffHunkIterator {
Expand Down Expand Up @@ -674,7 +659,10 @@ impl<'diff, 'input> Iterator for DiffHunkIterator<'diff, 'input> {
pub fn diff<'a, T: AsRef<[u8]> + ?Sized + 'a>(
inputs: impl IntoIterator<Item = &'a T>,
) -> Vec<DiffHunk<'a>> {
Diff::default_refinement(inputs).hunks().collect()
let mut diff = Diff::for_tokenizer(inputs, find_line_ranges);
diff.refine_changed_regions(find_word_ranges);
diff.refine_changed_regions(find_nonword_ranges);
diff.hunks().collect()
}

#[cfg(test)]
Expand Down

0 comments on commit 6101a66

Please sign in to comment.