Strict common-affix detection: returns the maximal common prefix and suffix without any reduction. Used by the record path so that pure insertions stay as pure insertions in the produced diff (which the graph layer then maps to targeted vertex operations). The relaxed sibling [`common_affixes`] applies a suffix-limiting heuristic that's useful for the display path but corrupts patch-theory semant
(old: &[T], new: &[T])
| 425 | /// [`common_affixes`] applies a suffix-limiting heuristic that's useful |
| 426 | /// for the display path but corrupts patch-theory semantics. |
| 427 | fn common_affixes_strict<T: PartialEq>(old: &[T], new: &[T]) -> (usize, usize) { |
| 428 | let prefix_len = old |
| 429 | .iter() |
| 430 | .zip(new.iter()) |
| 431 | .take_while(|(a, b)| a == b) |
| 432 | .count(); |
| 433 | |
| 434 | let remaining_old = old.len() - prefix_len; |
| 435 | let remaining_new = new.len() - prefix_len; |
| 436 | let max_suffix = remaining_old.min(remaining_new); |
| 437 | |
| 438 | let suffix_len = old[prefix_len..] |
| 439 | .iter() |
| 440 | .rev() |
| 441 | .zip(new[prefix_len..].iter().rev()) |
| 442 | .take(max_suffix) |
| 443 | .take_while(|(a, b)| a == b) |
| 444 | .count(); |
| 445 | |
| 446 | (prefix_len, suffix_len) |
| 447 | } |
| 448 | |
| 449 | /// Find the length of common prefix and suffix between two sequences, |
| 450 | /// applying the **suffix-limiting heuristic** used by the display path. |
no test coverage detected