diff options
Diffstat (limited to 'vendor/similar/src/algorithms/lcs.rs')
-rw-r--r-- | vendor/similar/src/algorithms/lcs.rs | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/vendor/similar/src/algorithms/lcs.rs b/vendor/similar/src/algorithms/lcs.rs index 6d1af687e..5eb3a63d0 100644 --- a/vendor/similar/src/algorithms/lcs.rs +++ b/vendor/similar/src/algorithms/lcs.rs @@ -64,6 +64,12 @@ where let common_prefix_len = common_prefix_len(old, old_range.clone(), new, new_range.clone()); let common_suffix_len = common_suffix_len(old, old_range.clone(), new, new_range.clone()); + // If the sequences are not different then we're done + if common_prefix_len == old_range.len() && (old_range.len() == new_range.len()) { + d.equal(0, 0, old_range.len())?; + return Ok(()); + } + let maybe_table = make_table( old, common_prefix_len..(old_range.len() - common_suffix_len), @@ -218,3 +224,13 @@ fn test_pat() { diff(&mut d, a, 0..a.len(), b, 0..b.len()).unwrap(); insta::assert_debug_snapshot!(d.ops()); } + +#[test] +fn test_same() { + let a: &[usize] = &[0, 1, 2, 3, 4, 4, 4, 5]; + let b: &[usize] = &[0, 1, 2, 3, 4, 4, 4, 5]; + + let mut d = crate::algorithms::Capture::new(); + diff(&mut d, a, 0..a.len(), b, 0..b.len()).unwrap(); + insta::assert_debug_snapshot!(d.ops()); +} |