Recursively apply patience diff to a region. # Arguments `old` - Slice of the old sequence for this region `new` - Slice of the new sequence for this region `old_offset` - Offset of this region in the original old sequence `new_offset` - Offset of this region in the original new sequence
(
old: &[Line<'a>],
new: &[Line<'a>],
old_offset: usize,
new_offset: usize,
)
| 106 | /// * `old_offset` - Offset of this region in the original old sequence |
| 107 | /// * `new_offset` - Offset of this region in the original new sequence |
| 108 | fn patience_diff_recursive<'a>( |
| 109 | old: &[Line<'a>], |
| 110 | new: &[Line<'a>], |
| 111 | old_offset: usize, |
| 112 | new_offset: usize, |
| 113 | ) -> DiffResult { |
| 114 | // Base cases |
| 115 | if old.is_empty() && new.is_empty() { |
| 116 | return DiffResult::new(); |
| 117 | } |
| 118 | if old.is_empty() { |
| 119 | let mut result = DiffResult::new(); |
| 120 | result.push(DiffOp::insert(old_offset, new_offset, new.len())); |
| 121 | return result; |
| 122 | } |
| 123 | if new.is_empty() { |
| 124 | let mut result = DiffResult::new(); |
| 125 | result.push(DiffOp::delete(old_offset, new_offset, old.len())); |
| 126 | return result; |
| 127 | } |
| 128 | |
| 129 | // Find unique lines and their matches |
| 130 | let matches = find_unique_matches(old, new); |
| 131 | |
| 132 | if matches.is_empty() { |
| 133 | // No unique matches - fall back to Myers |
| 134 | let mut result = myers::diff(old, new); |
| 135 | result.adjust_offsets(old_offset); |
| 136 | return result; |
| 137 | } |
| 138 | |
| 139 | // Find the Longest Increasing Subsequence of matches |
| 140 | let lis = longest_increasing_subsequence(&matches); |
| 141 | |
| 142 | if lis.is_empty() { |
| 143 | // No LIS (shouldn't happen if matches is non-empty, but be safe) |
| 144 | let mut result = myers::diff(old, new); |
| 145 | result.adjust_offsets(old_offset); |
| 146 | return result; |
| 147 | } |
| 148 | |
| 149 | // Build the diff by processing regions between LIS anchors |
| 150 | diff_with_anchors(old, new, old_offset, new_offset, &lis) |
| 151 | } |
| 152 | |
| 153 | /// A match between unique lines in old and new sequences. |
| 154 | #[derive(Debug, Clone, Copy)] |
no test coverage detected