check for identical sequences in lcs to avoid overflow panic (#43)
This commit is contained in:
parent
77c20faf94
commit
679c32ddee
2 changed files with 28 additions and 0 deletions
|
|
@ -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());
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue