summaryrefslogtreecommitdiffstats
path: root/vendor/similar/src/algorithms
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/similar/src/algorithms')
-rw-r--r--vendor/similar/src/algorithms/lcs.rs16
-rw-r--r--vendor/similar/src/algorithms/myers.rs2
-rw-r--r--vendor/similar/src/algorithms/snapshots/similar__algorithms__lcs__same.snap12
-rw-r--r--vendor/similar/src/algorithms/utils.rs2
4 files changed, 30 insertions, 2 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());
+}
diff --git a/vendor/similar/src/algorithms/myers.rs b/vendor/similar/src/algorithms/myers.rs
index 542c7ed75..8a0c21dbe 100644
--- a/vendor/similar/src/algorithms/myers.rs
+++ b/vendor/similar/src/algorithms/myers.rs
@@ -12,7 +12,7 @@
//! # Heuristics
//!
//! At present this implementation of Myers' does not implement any more advanced
-//! heuristics that would solve some pathological cases. For instane passing two
+//! heuristics that would solve some pathological cases. For instance passing two
//! large and completely distinct sequences to the algorithm will make it spin
//! without making reasonable progress. Currently the only protection in the
//! library against this is to pass a deadline to the diffing algorithm.
diff --git a/vendor/similar/src/algorithms/snapshots/similar__algorithms__lcs__same.snap b/vendor/similar/src/algorithms/snapshots/similar__algorithms__lcs__same.snap
new file mode 100644
index 000000000..4b9511b41
--- /dev/null
+++ b/vendor/similar/src/algorithms/snapshots/similar__algorithms__lcs__same.snap
@@ -0,0 +1,12 @@
+---
+source: src/algorithms/lcs.rs
+assertion_line: 235
+expression: d.ops()
+---
+[
+ Equal {
+ old_index: 0,
+ new_index: 0,
+ len: 8,
+ },
+]
diff --git a/vendor/similar/src/algorithms/utils.rs b/vendor/similar/src/algorithms/utils.rs
index 0d14ac799..812f97ddd 100644
--- a/vendor/similar/src/algorithms/utils.rs
+++ b/vendor/similar/src/algorithms/utils.rs
@@ -11,7 +11,7 @@ pub fn is_empty_range<T: PartialOrd<T>>(range: &Range<T>) -> bool {
!(range.start < range.end)
}
-/// Represents an item in the vector returend by [`unique`].
+/// Represents an item in the vector returned by [`unique`].
///
/// It compares like the underlying item does it was created from but
/// carries the index it was originally created from.