From 6101a66a765adc3bc764701e0c8d922e6f16dab8 Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Fri, 16 Aug 2024 16:32:24 +0900 Subject: [PATCH] diff: inline Diff::default_refinement() in diff() There are no callers other than tests and benches. --- lib/src/diff.rs | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/lib/src/diff.rs b/lib/src/diff.rs index 2e0bd27920..59ea147e76 100644 --- a/lib/src/diff.rs +++ b/lib/src/diff.rs @@ -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 + ?Sized + 'input>( - inputs: impl IntoIterator, - ) -> 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 { @@ -674,7 +659,10 @@ impl<'diff, 'input> Iterator for DiffHunkIterator<'diff, 'input> { pub fn diff<'a, T: AsRef<[u8]> + ?Sized + 'a>( inputs: impl IntoIterator, ) -> Vec> { - 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)]