| 1 | //! [![github]](https://github.com/dtolnay/dissimilar) [![crates-io]](https://crates.io/crates/dissimilar) [![docs-rs]](https://docs.rs/dissimilar) |
| 2 | //! |
| 3 | //! [github]: https://img.shields.io/badge/github-8da0cb?style=for-the-badge&labelColor=555555&logo=github |
| 4 | //! [crates-io]: https://img.shields.io/badge/crates.io-fc8d62?style=for-the-badge&labelColor=555555&logo=rust |
| 5 | //! [docs-rs]: https://img.shields.io/badge/docs.rs-66c2a5?style=for-the-badge&labelColor=555555&logoColor=white&logo=data:image/svg+xml;base64,PHN2ZyByb2xlPSJpbWciIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgdmlld0JveD0iMCAwIDUxMiA1MTIiPjxwYXRoIGZpbGw9IiNmNWY1ZjUiIGQ9Ik00ODguNiAyNTAuMkwzOTIgMjE0VjEwNS41YzAtMTUtOS4zLTI4LjQtMjMuNC0zMy43bC0xMDAtMzcuNWMtOC4xLTMuMS0xNy4xLTMuMS0yNS4zIDBsLTEwMCAzNy41Yy0xNC4xIDUuMy0yMy40IDE4LjctMjMuNCAzMy43VjIxNGwtOTYuNiAzNi4yQzkuMyAyNTUuNSAwIDI2OC45IDAgMjgzLjlWMzk0YzAgMTMuNiA3LjcgMjYuMSAxOS45IDMyLjJsMTAwIDUwYzEwLjEgNS4xIDIyLjEgNS4xIDMyLjIgMGwxMDMuOS01MiAxMDMuOSA1MmMxMC4xIDUuMSAyMi4xIDUuMSAzMi4yIDBsMTAwLTUwYzEyLjItNi4xIDE5LjktMTguNiAxOS45LTMyLjJWMjgzLjljMC0xNS05LjMtMjguNC0yMy40LTMzLjd6TTM1OCAyMTQuOGwtODUgMzEuOXYtNjguMmw4NS0zN3Y3My4zek0xNTQgMTA0LjFsMTAyLTM4LjIgMTAyIDM4LjJ2LjZsLTEwMiA0MS40LTEwMi00MS40di0uNnptODQgMjkxLjFsLTg1IDQyLjV2LTc5LjFsODUtMzguOHY3NS40em0wLTExMmwtMTAyIDQxLjQtMTAyLTQxLjR2LS42bDEwMi0zOC4yIDEwMiAzOC4ydi42em0yNDAgMTEybC04NSA0Mi41di03OS4xbDg1LTM4Ljh2NzUuNHptMC0xMTJsLTEwMiA0MS40LTEwMi00MS40di0uNmwxMDItMzguMiAxMDIgMzguMnYuNnoiPjwvcGF0aD48L3N2Zz4K |
| 6 | //! |
| 7 | //! <br> |
| 8 | //! |
| 9 | //! ## Diff library with semantic cleanup, based on Google's diff-match-patch |
| 10 | //! |
| 11 | //! This library is a port of the Diff component of [Diff Match Patch] to Rust. |
| 12 | //! The diff implementation is based on [Myers' diff algorithm] but includes |
| 13 | //! some [semantic cleanups] to increase human readability by factoring out |
| 14 | //! commonalities which are likely to be coincidental. |
| 15 | //! |
| 16 | //! Diff Match Patch was originally built in 2006 to power Google Docs. |
| 17 | //! |
| 18 | //! # Interface |
| 19 | //! |
| 20 | //! Here is the entire API of the Rust implementation. It operates on borrowed |
| 21 | //! strings and the return value of the diff algorithm is a vector of chunks |
| 22 | //! pointing into slices of those input strings. |
| 23 | //! |
| 24 | //! ``` |
| 25 | //! pub enum Chunk<'a> { |
| 26 | //! Equal(&'a str), |
| 27 | //! Delete(&'a str), |
| 28 | //! Insert(&'a str), |
| 29 | //! } |
| 30 | //! |
| 31 | //! # const IGNORE: &str = stringify! { |
| 32 | //! pub fn diff(text1: &str, text2: &str) -> Vec<Chunk>; |
| 33 | //! # }; |
| 34 | //! ``` |
| 35 | //! |
| 36 | //! [Diff Match Patch]: https://github.com/google/diff-match-patch |
| 37 | //! [Myers' diff algorithm]: https://neil.fraser.name/writing/diff/myers.pdf |
| 38 | //! [semantic cleanups]: https://neil.fraser.name/writing/diff/ |
| 39 | |
| 40 | #![doc(html_root_url = "https://docs.rs/dissimilar/1.0.2")] |
| 41 | #![allow( |
| 42 | clippy::blocks_in_if_conditions, |
| 43 | clippy::collapsible_if, |
| 44 | clippy::comparison_chain, |
| 45 | clippy::new_without_default |
| 46 | )] |
| 47 | |
| 48 | mod findrust-analyzer cargo dissimilar 1.0.2 find/; |
| 49 | mod rangerust-analyzer cargo dissimilar 1.0.2 range/; |
| 50 | |
| 51 | #[cfg(test)] |
| 52 | mod testsrust-analyzer cargo dissimilar 1.0.2 tests/; |
| 53 | |
| 54 | use craterust-analyzer cargo dissimilar 1.0.2 crate/::rangerust-analyzer cargo dissimilar 1.0.2 range/::{bytesrust-analyzer cargo dissimilar 1.0.2 range/bytes()., strrust-analyzer cargo dissimilar 1.0.2 range/str()., Rangerust-analyzer cargo dissimilar 1.0.2 range/Range#}; |
| 55 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/; |
| 56 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::collectionsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/::VecDequerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/VecDeque#; |
| 57 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::{selfrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug#}; |
| 58 | |
| 59 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:)] |
| 60 | pub enum Chunkrust-analyzer cargo dissimilar 1.0.2 Chunk#<'a> { |
| 61 | Equalrust-analyzer cargo dissimilar 1.0.2 Chunk#Equal#(&'a str), |
| 62 | Deleterust-analyzer cargo dissimilar 1.0.2 Chunk#Delete#(&'a str), |
| 63 | Insertrust-analyzer cargo dissimilar 1.0.2 Chunk#Insert#(&'a str), |
| 64 | } |
| 65 | |
| 66 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:)] |
| 67 | enum Diffrust-analyzer cargo dissimilar 1.0.2 Diff#<'a, 'b> { |
| 68 | Equalrust-analyzer cargo dissimilar 1.0.2 Diff#Equal#(Rangerust-analyzer cargo dissimilar 1.0.2 range/Range#<'a>, Rangerust-analyzer cargo dissimilar 1.0.2 range/Range#<'b>), |
| 69 | Deleterust-analyzer cargo dissimilar 1.0.2 Diff#Delete#(Rangerust-analyzer cargo dissimilar 1.0.2 range/Range#<'a>), |
| 70 | Insertrust-analyzer cargo dissimilar 1.0.2 Diff#Insert#(Rangerust-analyzer cargo dissimilar 1.0.2 range/Range#<'b>), |
| 71 | } |
| 72 | |
| 73 | impl<'tmp, 'a: 'tmp, 'b: 'tmp> Diffrust-analyzer cargo dissimilar 1.0.2 Diff#<'a, 'b> { |
| 74 | fn textrust-analyzer cargo dissimilar 1.0.2 impl#[`Diff<'a, 'b>`]text().(&self) -> Rangerust-analyzer cargo dissimilar 1.0.2 range/Range#<'tmp> { |
| 75 | match *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self { |
| 76 | Diffrust-analyzer cargo dissimilar 1.0.2 Diff#::Equalrust-analyzer cargo dissimilar 1.0.2 Diff#Equal#(range, _) | Diffrust-analyzer cargo dissimilar 1.0.2 Diff#::Deleterust-analyzer cargo dissimilar 1.0.2 Diff#Delete#(range) | Diffrust-analyzer cargo dissimilar 1.0.2 Diff#::Insertrust-analyzer cargo dissimilar 1.0.2 Diff#Insert#(range) => range, |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | fn grow_leftrust-analyzer cargo dissimilar 1.0.2 impl#[`Diff<'a, 'b>`]grow_left().(&mut self, increment: usize) { |
| 81 | self.for_eachrust-analyzer cargo dissimilar 1.0.2 impl#[`Diff<'a, 'b>`]for_each().(|range| { |
| 82 | range.offsetrust-analyzer cargo dissimilar 1.0.2 range/Range#offset. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().increment; |
| 83 | range.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().increment; |
| 84 | }); |
| 85 | } |
| 86 | |
| 87 | fn grow_rightrust-analyzer cargo dissimilar 1.0.2 impl#[`Diff<'a, 'b>`]grow_right().(&mut self, increment: usize) { |
| 88 | self.for_eachrust-analyzer cargo dissimilar 1.0.2 impl#[`Diff<'a, 'b>`]for_each().(|range| range.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().increment); |
| 89 | } |
| 90 | |
| 91 | fn shift_leftrust-analyzer cargo dissimilar 1.0.2 impl#[`Diff<'a, 'b>`]shift_left().(&mut self, increment: usize) { |
| 92 | self.for_eachrust-analyzer cargo dissimilar 1.0.2 impl#[`Diff<'a, 'b>`]for_each().(|range| range.offsetrust-analyzer cargo dissimilar 1.0.2 range/Range#offset. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().increment); |
| 93 | } |
| 94 | |
| 95 | fn shift_rightrust-analyzer cargo dissimilar 1.0.2 impl#[`Diff<'a, 'b>`]shift_right().(&mut self, increment: usize) { |
| 96 | self.for_eachrust-analyzer cargo dissimilar 1.0.2 impl#[`Diff<'a, 'b>`]for_each().(|range| range.offsetrust-analyzer cargo dissimilar 1.0.2 range/Range#offset. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().increment); |
| 97 | } |
| 98 | |
| 99 | fn for_eachrust-analyzer cargo dissimilar 1.0.2 impl#[`Diff<'a, 'b>`]for_each().(&mut self, f: impl Fnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/Fn#(&mut Rangerust-analyzer cargo dissimilar 1.0.2 range/Range#)) { |
| 100 | match self { |
| 101 | Diffrust-analyzer cargo dissimilar 1.0.2 Diff#::Equalrust-analyzer cargo dissimilar 1.0.2 Diff#Equal#(range1, range2) => { |
| 102 | f(range1); |
| 103 | f(range2); |
| 104 | } |
| 105 | Diffrust-analyzer cargo dissimilar 1.0.2 Diff#::Deleterust-analyzer cargo dissimilar 1.0.2 Diff#Delete#(range) => f(range), |
| 106 | Diffrust-analyzer cargo dissimilar 1.0.2 Diff#::Insertrust-analyzer cargo dissimilar 1.0.2 Diff#Insert#(range) => f(range), |
| 107 | } |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | pub fn diffrust-analyzer cargo dissimilar 1.0.2 diff().<'a>(text1: &'a str, text2: &'a str) -> Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Chunkrust-analyzer cargo dissimilar 1.0.2 Chunk#<'a>> { |
| 112 | let text1 = Rangerust-analyzer cargo dissimilar 1.0.2 range/Range#::newrust-analyzer cargo dissimilar 1.0.2 range/impl#[`Range<'a>`]new().(text1, ..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#); |
| 113 | let text2 = Rangerust-analyzer cargo dissimilar 1.0.2 range/Range#::newrust-analyzer cargo dissimilar 1.0.2 range/impl#[`Range<'a>`]new().(text2, ..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#); |
| 114 | let mut solution = mainrust-analyzer cargo dissimilar 1.0.2 main().(text1, text2); |
| 115 | cleanup_char_boundaryrust-analyzer cargo dissimilar 1.0.2 cleanup_char_boundary().(&mut solution); |
| 116 | cleanup_semanticrust-analyzer cargo dissimilar 1.0.2 cleanup_semantic().(&mut solution); |
| 117 | cleanup_mergerust-analyzer cargo dissimilar 1.0.2 cleanup_merge().(&mut solution); |
| 118 | solution.diffsrust-analyzer cargo dissimilar 1.0.2 Solution#diffs..into_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][IntoIterator]into_iter().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(Chunkrust-analyzer cargo dissimilar 1.0.2 Chunk#::fromrust-analyzer cargo dissimilar 1.0.2 impl#[`Chunk<'a>`][`From<Diff<'a, 'a>>`]from().).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().() |
| 119 | } |
| 120 | |
| 121 | struct Solutionrust-analyzer cargo dissimilar 1.0.2 Solution#<'a, 'b> { |
| 122 | text1rust-analyzer cargo dissimilar 1.0.2 Solution#text1.: Rangerust-analyzer cargo dissimilar 1.0.2 range/Range#<'a>, |
| 123 | text2rust-analyzer cargo dissimilar 1.0.2 Solution#text2.: Rangerust-analyzer cargo dissimilar 1.0.2 range/Range#<'b>, |
| 124 | diffsrust-analyzer cargo dissimilar 1.0.2 Solution#diffs.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Diffrust-analyzer cargo dissimilar 1.0.2 Diff#<'a, 'b>>, |
| 125 | utf8rust-analyzer cargo dissimilar 1.0.2 Solution#utf8.: bool, |
| 126 | } |
| 127 | |
| 128 | fn mainrust-analyzer cargo dissimilar 1.0.2 main().<'a, 'b>(mut text1: Rangerust-analyzer cargo dissimilar 1.0.2 range/Range#<'a>, mut text2: Rangerust-analyzer cargo dissimilar 1.0.2 range/Range#<'b>) -> Solutionrust-analyzer cargo dissimilar 1.0.2 Solution#<'a, 'b> { |
| 129 | let whole1 = text1; |
| 130 | let whole2 = text2; |
| 131 | |
| 132 | // Trim off common prefix. |
| 133 | let common_prefix_len = common_prefix_bytesrust-analyzer cargo dissimilar 1.0.2 common_prefix_bytes().(text1, text2); |
| 134 | let common_prefix = Diffrust-analyzer cargo dissimilar 1.0.2 Diff#::Equalrust-analyzer cargo dissimilar 1.0.2 Diff#Equal#( |
| 135 | text1.substringrust-analyzer cargo dissimilar 1.0.2 range/impl#[`Range<'a>`]substring().(..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#common_prefix_len), |
| 136 | text2.substringrust-analyzer cargo dissimilar 1.0.2 range/impl#[`Range<'a>`]substring().(..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#common_prefix_len), |
| 137 | ); |
| 138 | text1 = text1.substringrust-analyzer cargo dissimilar 1.0.2 range/impl#[`Range<'a>`]substring().(common_prefix_len..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#); |
| 139 | text2 = text2.substringrust-analyzer cargo dissimilar 1.0.2 range/impl#[`Range<'a>`]substring().(common_prefix_len..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#); |
| 140 | |
| 141 | // Trim off common suffix. |
| 142 | let common_suffix_len = common_suffix_bytesrust-analyzer cargo dissimilar 1.0.2 common_suffix_bytes().(text1, text2); |
| 143 | let common_suffix = Diffrust-analyzer cargo dissimilar 1.0.2 Diff#::Equalrust-analyzer cargo dissimilar 1.0.2 Diff#Equal#( |
| 144 | text1.substringrust-analyzer cargo dissimilar 1.0.2 range/impl#[`Range<'a>`]substring().(text1.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().common_suffix_len..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#), |
| 145 | text2.substringrust-analyzer cargo dissimilar 1.0.2 range/impl#[`Range<'a>`]substring().(text2.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().common_suffix_len..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#), |
| 146 | ); |
| 147 | text1 = text1.substringrust-analyzer cargo dissimilar 1.0.2 range/impl#[`Range<'a>`]substring().(..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#text1.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().common_suffix_len); |
| 148 | text2 = text2.substringrust-analyzer cargo dissimilar 1.0.2 range/impl#[`Range<'a>`]substring().(..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#text2.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().common_suffix_len); |
| 149 | |
| 150 | // Compute the diff on the middle block. |
| 151 | let mut solution = Solutionrust-analyzer cargo dissimilar 1.0.2 Solution# { |
| 152 | text1rust-analyzer cargo dissimilar 1.0.2 Solution#text1.: whole1, |
| 153 | text2rust-analyzer cargo dissimilar 1.0.2 Solution#text2.: whole2, |
| 154 | diffsrust-analyzer cargo dissimilar 1.0.2 Solution#diffs.: computerust-analyzer cargo dissimilar 1.0.2 compute().(text1, text2), |
| 155 | utf8rust-analyzer cargo dissimilar 1.0.2 Solution#utf8.: false, |
| 156 | }; |
| 157 | |
| 158 | // Restore the prefix and suffix. |
| 159 | if common_prefix_len rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().0 { |
| 160 | solution.diffsrust-analyzer cargo dissimilar 1.0.2 Solution#diffs..insertrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]insert().(0, common_prefix); |
| 161 | } |
| 162 | if common_suffix_len rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().0 { |
| 163 | solution.diffsrust-analyzer cargo dissimilar 1.0.2 Solution#diffs..pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(common_suffix); |
| 164 | } |
| 165 | |
| 166 | cleanup_mergerust-analyzer cargo dissimilar 1.0.2 cleanup_merge().(&mut solution); |
| 167 | |
| 168 | solution |
| 169 | } |
| 170 | |
| 171 | // Find the differences between two texts. Assumes that the texts do not have |
| 172 | // any common prefix or suffix. |
| 173 | fn computerust-analyzer cargo dissimilar 1.0.2 compute().<'a, 'b>(text1: Rangerust-analyzer cargo dissimilar 1.0.2 range/Range#<'a>, text2: Rangerust-analyzer cargo dissimilar 1.0.2 range/Range#<'b>) -> Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Diffrust-analyzer cargo dissimilar 1.0.2 Diff#<'a, 'b>> { |
| 174 | match (text1.is_emptyrust-analyzer cargo dissimilar 1.0.2 range/impl#[`Range<'a>`]is_empty().(), text2.is_emptyrust-analyzer cargo dissimilar 1.0.2 range/impl#[`Range<'a>`]is_empty().()) { |
| 175 | (true, true) => return Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().(), |
| 176 | (true, false) => return vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![Diffrust-analyzer cargo dissimilar 1.0.2 Diff#::Insertrust-analyzer cargo dissimilar 1.0.2 Diff#Insert#(text2)], |
| 177 | (false, true) => return vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![Diffrust-analyzer cargo dissimilar 1.0.2 Diff#::Deleterust-analyzer cargo dissimilar 1.0.2 Diff#Delete#(text1)], |
| 178 | (false, false) => {} |
| 179 | } |
| 180 | |
| 181 | // Check for entire shorter text inside the longer text. |
| 182 | if text1.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().text2.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len. { |
| 183 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(i) = text1.findrust-analyzer cargo dissimilar 1.0.2 range/impl#[`Range<'a>`]find().(text2) { |
| 184 | return vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![ |
| 185 | Diffrust-analyzer cargo dissimilar 1.0.2 Diff#::Deleterust-analyzer cargo dissimilar 1.0.2 Diff#Delete#(text1.substringrust-analyzer cargo dissimilar 1.0.2 range/impl#[`Range<'a>`]substring().(..i)), |
| 186 | Diffrust-analyzer cargo dissimilar 1.0.2 Diff#::Equalrust-analyzer cargo dissimilar 1.0.2 Diff#Equal#(text1.substringrust-analyzer cargo dissimilar 1.0.2 range/impl#[`Range<'a>`]substring().(i..i +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). text2.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len.), text2), |
| 187 | Diffrust-analyzer cargo dissimilar 1.0.2 Diff#::Deleterust-analyzer cargo dissimilar 1.0.2 Diff#Delete#(text1.substringrust-analyzer cargo dissimilar 1.0.2 range/impl#[`Range<'a>`]substring().(i +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). text2.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len...)), |
| 188 | ]; |
| 189 | } |
| 190 | } else { |
| 191 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(i) = text2.findrust-analyzer cargo dissimilar 1.0.2 range/impl#[`Range<'a>`]find().(text1) { |
| 192 | return vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![ |
| 193 | Diffrust-analyzer cargo dissimilar 1.0.2 Diff#::Insertrust-analyzer cargo dissimilar 1.0.2 Diff#Insert#(text2.substringrust-analyzer cargo dissimilar 1.0.2 range/impl#[`Range<'a>`]substring().(..i)), |
| 194 | Diffrust-analyzer cargo dissimilar 1.0.2 Diff#::Equalrust-analyzer cargo dissimilar 1.0.2 Diff#Equal#(text1, text2.substringrust-analyzer cargo dissimilar 1.0.2 range/impl#[`Range<'a>`]substring().(i..i +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). text1.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len.)), |
| 195 | Diffrust-analyzer cargo dissimilar 1.0.2 Diff#::Insertrust-analyzer cargo dissimilar 1.0.2 Diff#Insert#(text2.substringrust-analyzer cargo dissimilar 1.0.2 range/impl#[`Range<'a>`]substring().(i +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). text1.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len...)), |
| 196 | ]; |
| 197 | } |
| 198 | } |
| 199 | |
| 200 | if text1.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().1 || text2.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().1 { |
| 201 | // Single character string. |
| 202 | // After the previous check, the character can't be an equality. |
| 203 | return vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![Diffrust-analyzer cargo dissimilar 1.0.2 Diff#::Deleterust-analyzer cargo dissimilar 1.0.2 Diff#Delete#(text1), Diffrust-analyzer cargo dissimilar 1.0.2 Diff#::Insertrust-analyzer cargo dissimilar 1.0.2 Diff#Insert#(text2)]; |
| 204 | } |
| 205 | |
| 206 | bisectrust-analyzer cargo dissimilar 1.0.2 bisect().(text1, text2) |
| 207 | } |
| 208 | |
| 209 | // Find the 'middle snake' of a diff, split the problem in two and return the |
| 210 | // recursively constructed diff. |
| 211 | // |
| 212 | // See Myers 1986 paper: An O(ND) Difference Algorithm and Its Variations. |
| 213 | fn bisectrust-analyzer cargo dissimilar 1.0.2 bisect().<'a, 'b>(text1: Rangerust-analyzer cargo dissimilar 1.0.2 range/Range#<'a>, text2: Rangerust-analyzer cargo dissimilar 1.0.2 range/Range#<'b>) -> Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Diffrust-analyzer cargo dissimilar 1.0.2 Diff#<'a, 'b>> { |
| 214 | let max_d = (text1.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().text2.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div().2; |
| 215 | let v_offset = max_d; |
| 216 | let v_len = 2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().max_d; |
| 217 | let mut v1 = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][Neg]neg().1isize; v_len]; |
| 218 | let mut v2 = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][Neg]neg().1isize; v_len]; |
| 219 | v1[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut().v_offset rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut(). = 0; |
| 220 | v2[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut().v_offset rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut(). = 0; |
| 221 | let delta = text1.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len. as isize rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`Sub<Self>`]sub().text2.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len. as isize; |
| 222 | // If the total number of characters is odd, then the front path will |
| 223 | // collide with the reverse path. |
| 224 | let front = delta rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`Rem<Self>`]rem().%rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`Rem<Self>`]rem(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`Rem<Self>`]rem().2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialEq<Self>`]ne().0; |
| 225 | // Offsets for start and end of k loop. |
| 226 | // Prevents mapping of space beyond the grid. |
| 227 | let mut k1start = 0; |
| 228 | let mut k1end = 0; |
| 229 | let mut k2start = 0; |
| 230 | let mut k2end = 0; |
| 231 | for d in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#max_d as isize { |
| 232 | // Walk the front path one step. |
| 233 | let mut k1 = -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][Neg]neg().d rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`Add<Self>`]add().k1start; |
| 234 | while k1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialOrd<Self>`]le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialOrd<Self>`]le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialOrd<Self>`]le().d rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`Sub<Self>`]sub().k1end { |
| 235 | let k1_offset = (v_offset as isize rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`Add<Self>`]add().k1) as usize; |
| 236 | let mut x1 = if k1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialEq<Self>`]eq().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][Neg]neg().d || (k1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialEq<Self>`]ne().d && v1[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().k1_offset rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().1]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialOrd<Self>`]lt().v1[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().k1_offset rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().) { |
| 237 | v1[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().k1_offset rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index(). |
| 238 | } else { |
| 239 | v1[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().k1_offset rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().1]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`Add<Self>`]add().1 |
| 240 | } as usize; |
| 241 | let mut y1 = (x1 as isize rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`Sub<Self>`]sub().k1) as usize; |
| 242 | if let (Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(s1), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(s2)) = (text1.getrust-analyzer cargo dissimilar 1.0.2 range/impl#[`Range<'a>`]get().(x1..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#), text2.getrust-analyzer cargo dissimilar 1.0.2 range/impl#[`Range<'a>`]get().(y1..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#)) { |
| 243 | let advance = common_prefix_bytesrust-analyzer cargo dissimilar 1.0.2 common_prefix_bytes().(s1, s2); |
| 244 | x1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().advance; |
| 245 | y1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().advance; |
| 246 | } |
| 247 | v1[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut().k1_offset]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut(). = x1 as isize; |
| 248 | if x1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().text1.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len. { |
| 249 | // Ran off the right of the graph. |
| 250 | k1end rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`AddAssign<Self>`]add_assign().2; |
| 251 | } else if y1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().text2.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len. { |
| 252 | // Ran off the bottom of the graph. |
| 253 | k1start rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`AddAssign<Self>`]add_assign().2; |
| 254 | } else if front { |
| 255 | let k2_offset = v_offset as isize rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`Add<Self>`]add().delta rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`Sub<Self>`]sub().k1; |
| 256 | if k2_offset rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialOrd<Self>`]ge().0 && k2_offset rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialOrd<Self>`]lt().v_len as isize && v2[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().k2_offset as usize]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialEq<Self>`]ne().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][Neg]neg().1 { |
| 257 | // Mirror x2 onto top-left coordinate system. |
| 258 | let x2 = text1.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len. as isize rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`Sub<Self>`]sub().v2[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().k2_offset as usize]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().; |
| 259 | if x1 as isize rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialOrd<Self>`]ge().x2 { |
| 260 | // Overlap detected. |
| 261 | return bisect_splitrust-analyzer cargo dissimilar 1.0.2 bisect_split().(text1, text2, x1, y1); |
| 262 | } |
| 263 | } |
| 264 | } |
| 265 | k1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`AddAssign<Self>`]add_assign().2; |
| 266 | } |
| 267 | |
| 268 | // Walk the reverse path one step. |
| 269 | let mut k2 = -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][Neg]neg().d rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`Add<Self>`]add().k2start; |
| 270 | while k2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialOrd<Self>`]le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialOrd<Self>`]le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialOrd<Self>`]le().d rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`Sub<Self>`]sub().k2end { |
| 271 | let k2_offset = (v_offset as isize rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`Add<Self>`]add().k2) as usize; |
| 272 | let mut x2 = if k2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialEq<Self>`]eq().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][Neg]neg().d || (k2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialEq<Self>`]ne().d && v2[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().k2_offset rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().1]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialOrd<Self>`]lt().v2[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().k2_offset rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().) { |
| 273 | v2[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().k2_offset rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index(). |
| 274 | } else { |
| 275 | v2[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().k2_offset rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().1]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`Add<Self>`]add().1 |
| 276 | } as usize; |
| 277 | let mut y2 = (x2 as isize rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`Sub<Self>`]sub().k2) as usize; |
| 278 | if x2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().text1.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len. && y2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().text2.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len. { |
| 279 | let advance = common_suffix_bytesrust-analyzer cargo dissimilar 1.0.2 common_suffix_bytes().( |
| 280 | text1.substringrust-analyzer cargo dissimilar 1.0.2 range/impl#[`Range<'a>`]substring().(..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#text1.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().x2), |
| 281 | text2.substringrust-analyzer cargo dissimilar 1.0.2 range/impl#[`Range<'a>`]substring().(..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#text2.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().y2), |
| 282 | ); |
| 283 | x2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().advance; |
| 284 | y2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().advance; |
| 285 | } |
| 286 | v2[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut().k2_offset]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut(). = x2 as isize; |
| 287 | if x2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().text1.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len. { |
| 288 | // Ran off the left of the graph. |
| 289 | k2end rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`AddAssign<Self>`]add_assign().2; |
| 290 | } else if y2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().text2.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len. { |
| 291 | // Ran off the top of the graph. |
| 292 | k2start rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`AddAssign<Self>`]add_assign().2; |
| 293 | } else if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().front { |
| 294 | let k1_offset = v_offset as isize rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`Add<Self>`]add().delta rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`Sub<Self>`]sub().k2; |
| 295 | if k1_offset rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialOrd<Self>`]ge().0 && k1_offset rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialOrd<Self>`]lt().v_len as isize && v1[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().k1_offset as usize]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialEq<Self>`]ne().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][Neg]neg().1 { |
| 296 | let x1 = v1[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().k1_offset as usize]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index(). as usize; |
| 297 | let y1 = v_offset rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().x1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().k1_offset as usize; |
| 298 | // Mirror x2 onto top-left coordinate system. |
| 299 | x2 = text1.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().x2; |
| 300 | if x1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().x2 { |
| 301 | // Overlap detected. |
| 302 | return bisect_splitrust-analyzer cargo dissimilar 1.0.2 bisect_split().(text1, text2, x1, y1); |
| 303 | } |
| 304 | } |
| 305 | } |
| 306 | k2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`AddAssign<Self>`]add_assign().2; |
| 307 | } |
| 308 | } |
| 309 | // Number of diffs equals number of characters, no commonality at all. |
| 310 | vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![Diffrust-analyzer cargo dissimilar 1.0.2 Diff#::Deleterust-analyzer cargo dissimilar 1.0.2 Diff#Delete#(text1), Diffrust-analyzer cargo dissimilar 1.0.2 Diff#::Insertrust-analyzer cargo dissimilar 1.0.2 Diff#Insert#(text2)] |
| 311 | } |
| 312 | |
| 313 | // Given the location of the 'middle snake', split the diff in two parts and |
| 314 | // recurse. |
| 315 | fn bisect_splitrust-analyzer cargo dissimilar 1.0.2 bisect_split().<'a, 'b>( |
| 316 | text1: Rangerust-analyzer cargo dissimilar 1.0.2 range/Range#<'a>, |
| 317 | text2: Rangerust-analyzer cargo dissimilar 1.0.2 range/Range#<'b>, |
| 318 | x: usize, |
| 319 | y: usize, |
| 320 | ) -> Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Diffrust-analyzer cargo dissimilar 1.0.2 Diff#<'a, 'b>> { |
| 321 | let (text1a, text1b) = text1.split_atrust-analyzer cargo dissimilar 1.0.2 range/impl#[`Range<'a>`]split_at().(x); |
| 322 | let (text2a, text2b) = text2.split_atrust-analyzer cargo dissimilar 1.0.2 range/impl#[`Range<'a>`]split_at().(y); |
| 323 | |
| 324 | // Compute both diffs serially. |
| 325 | let mut diffs = mainrust-analyzer cargo dissimilar 1.0.2 main().(text1a, text2a).diffsrust-analyzer cargo dissimilar 1.0.2 Solution#diffs.; |
| 326 | diffs.extendrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Extend<T>`]extend().(mainrust-analyzer cargo dissimilar 1.0.2 main().(text1b, text2b).diffsrust-analyzer cargo dissimilar 1.0.2 Solution#diffs.); |
| 327 | |
| 328 | diffs |
| 329 | } |
| 330 | |
| 331 | // Determine the length of the common prefix of two strings. |
| 332 | fn common_prefixrust-analyzer cargo dissimilar 1.0.2 common_prefix().(text1: Rangerust-analyzer cargo dissimilar 1.0.2 range/Range#, text2: Rangerust-analyzer cargo dissimilar 1.0.2 range/Range#) -> usize { |
| 333 | for ((i, ch1), ch2) in text1.char_indicesrust-analyzer cargo dissimilar 1.0.2 range/impl#[`Range<'a>`]char_indices().().ziprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#zip().(text2.charsrust-analyzer cargo dissimilar 1.0.2 range/impl#[`Range<'a>`]chars().()) { |
| 334 | if ch1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]ne().ch2 { |
| 335 | return i; |
| 336 | } |
| 337 | } |
| 338 | cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/::minrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/min().(text1.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len., text2.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len.) |
| 339 | } |
| 340 | |
| 341 | // Determine the length of the common suffix of two strings. |
| 342 | fn common_suffixrust-analyzer cargo dissimilar 1.0.2 common_suffix().(text1: Rangerust-analyzer cargo dissimilar 1.0.2 range/Range#, text2: Rangerust-analyzer cargo dissimilar 1.0.2 range/Range#) -> usize { |
| 343 | for ((i, ch1), ch2) in text1.char_indicesrust-analyzer cargo dissimilar 1.0.2 range/impl#[`Range<'a>`]char_indices().().revrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#rev().().ziprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#zip().(text2.charsrust-analyzer cargo dissimilar 1.0.2 range/impl#[`Range<'a>`]chars().().revrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#rev().()) { |
| 344 | if ch1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]ne().ch2 { |
| 345 | return text1.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().ch1.len_utf8rust-analyzer cargo core https://github.com/rust-lang/rust/library/core char/methods/impl#[char]len_utf8().(); |
| 346 | } |
| 347 | } |
| 348 | cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/::minrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/min().(text1.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len., text2.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len.) |
| 349 | } |
| 350 | |
| 351 | fn common_prefix_bytesrust-analyzer cargo dissimilar 1.0.2 common_prefix_bytes().(text1: Rangerust-analyzer cargo dissimilar 1.0.2 range/Range#, text2: Rangerust-analyzer cargo dissimilar 1.0.2 range/Range#) -> usize { |
| 352 | for (i, (b1, b2)) in text1.bytesrust-analyzer cargo dissimilar 1.0.2 range/impl#[`Range<'a>`]bytes().().ziprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#zip().(text2.bytesrust-analyzer cargo dissimilar 1.0.2 range/impl#[`Range<'a>`]bytes().()).enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().() { |
| 353 | if b1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne().b2 { |
| 354 | return i; |
| 355 | } |
| 356 | } |
| 357 | cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/::minrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/min().(text1.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len., text2.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len.) |
| 358 | } |
| 359 | |
| 360 | fn common_suffix_bytesrust-analyzer cargo dissimilar 1.0.2 common_suffix_bytes().(text1: Rangerust-analyzer cargo dissimilar 1.0.2 range/Range#, text2: Rangerust-analyzer cargo dissimilar 1.0.2 range/Range#) -> usize { |
| 361 | for (i, (b1, b2)) in text1.bytesrust-analyzer cargo dissimilar 1.0.2 range/impl#[`Range<'a>`]bytes().().revrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#rev().().ziprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#zip().(text2.bytesrust-analyzer cargo dissimilar 1.0.2 range/impl#[`Range<'a>`]bytes().().revrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#rev().()).enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().() { |
| 362 | if b1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne().b2 { |
| 363 | return i; |
| 364 | } |
| 365 | } |
| 366 | cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/::minrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/min().(text1.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len., text2.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len.) |
| 367 | } |
| 368 | |
| 369 | // Determine if the suffix of one string is the prefix of another. |
| 370 | // |
| 371 | // Returns the number of characters common to the end of the first string and |
| 372 | // the start of the second string. |
| 373 | fn common_overlaprust-analyzer cargo dissimilar 1.0.2 common_overlap().(mut text1: Rangerust-analyzer cargo dissimilar 1.0.2 range/Range#, mut text2: Rangerust-analyzer cargo dissimilar 1.0.2 range/Range#) -> usize { |
| 374 | // Eliminate the null case. |
| 375 | if text1.is_emptyrust-analyzer cargo dissimilar 1.0.2 range/impl#[`Range<'a>`]is_empty().() || text2.is_emptyrust-analyzer cargo dissimilar 1.0.2 range/impl#[`Range<'a>`]is_empty().() { |
| 376 | return 0; |
| 377 | } |
| 378 | // Truncate the longer string. |
| 379 | if text1.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().text2.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len. { |
| 380 | text1 = text1.substringrust-analyzer cargo dissimilar 1.0.2 range/impl#[`Range<'a>`]substring().(text1.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().text2.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#); |
| 381 | } else if text1.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().text2.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len. { |
| 382 | text2 = text2.substringrust-analyzer cargo dissimilar 1.0.2 range/impl#[`Range<'a>`]substring().(..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#text1.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len.); |
| 383 | } |
| 384 | // Quick check for the worst case. |
| 385 | if bytesrust-analyzer cargo dissimilar 1.0.2 range/bytes().(text1) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().bytesrust-analyzer cargo dissimilar 1.0.2 range/bytes().(text2) { |
| 386 | return text1.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len.; |
| 387 | } |
| 388 | |
| 389 | // Start by looking for a single character match |
| 390 | // and increase length until no match is found. |
| 391 | // Performance analysis: https://neil.fraser.name/news/2010/11/04/ |
| 392 | let mut best = 0; |
| 393 | let mut length = 1; |
| 394 | loop { |
| 395 | let pattern = text1.substringrust-analyzer cargo dissimilar 1.0.2 range/impl#[`Range<'a>`]substring().(text1.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().length..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#); |
| 396 | let found = match text2.findrust-analyzer cargo dissimilar 1.0.2 range/impl#[`Range<'a>`]find().(pattern) { |
| 397 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(found) => found, |
| 398 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => return best, |
| 399 | }; |
| 400 | length rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().found; |
| 401 | if found rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().0 |
| 402 | || bytesrust-analyzer cargo dissimilar 1.0.2 range/bytes().(text1.substringrust-analyzer cargo dissimilar 1.0.2 range/impl#[`Range<'a>`]substring().(text1.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().length..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#)) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().bytesrust-analyzer cargo dissimilar 1.0.2 range/bytes().(text2.substringrust-analyzer cargo dissimilar 1.0.2 range/impl#[`Range<'a>`]substring().(..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#length)) |
| 403 | { |
| 404 | best = length; |
| 405 | length rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1; |
| 406 | } |
| 407 | } |
| 408 | } |
| 409 | |
| 410 | fn cleanup_char_boundaryrust-analyzer cargo dissimilar 1.0.2 cleanup_char_boundary().(solution: &mut Solutionrust-analyzer cargo dissimilar 1.0.2 Solution#) { |
| 411 | fn boundary_downrust-analyzer cargo dissimilar 1.0.2 boundary_down().(doc: &str, pos: usize) -> usize { |
| 412 | let mut adjust = 0; |
| 413 | while !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().doc.is_char_boundaryrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]is_char_boundary().(pos rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().adjust) { |
| 414 | adjust rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1; |
| 415 | } |
| 416 | adjust |
| 417 | } |
| 418 | |
| 419 | fn boundary_uprust-analyzer cargo dissimilar 1.0.2 boundary_up().(doc: &str, pos: usize) -> usize { |
| 420 | let mut adjust = 0; |
| 421 | while !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().doc.is_char_boundaryrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]is_char_boundary().(pos rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().adjust) { |
| 422 | adjust rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1; |
| 423 | } |
| 424 | adjust |
| 425 | } |
| 426 | |
| 427 | for diff in &mut solution.diffsrust-analyzer cargo dissimilar 1.0.2 Solution#diffs. { |
| 428 | match diff { |
| 429 | Diffrust-analyzer cargo dissimilar 1.0.2 Diff#::Equalrust-analyzer cargo dissimilar 1.0.2 Diff#Equal#(range1, range2) => { |
| 430 | let adjust = boundary_uprust-analyzer cargo dissimilar 1.0.2 boundary_up().(range1.docrust-analyzer cargo dissimilar 1.0.2 range/Range#doc., range1.offsetrust-analyzer cargo dissimilar 1.0.2 range/Range#offset.); |
| 431 | range1.offsetrust-analyzer cargo dissimilar 1.0.2 range/Range#offset. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().adjust; |
| 432 | range1.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().adjust; |
| 433 | range2.offsetrust-analyzer cargo dissimilar 1.0.2 range/Range#offset. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().adjust; |
| 434 | range2.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().adjust; |
| 435 | let adjust = boundary_downrust-analyzer cargo dissimilar 1.0.2 boundary_down().(range1.docrust-analyzer cargo dissimilar 1.0.2 range/Range#doc., range1.offsetrust-analyzer cargo dissimilar 1.0.2 range/Range#offset. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().range1.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len.); |
| 436 | range1.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().adjust; |
| 437 | range2.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().adjust; |
| 438 | } |
| 439 | Diffrust-analyzer cargo dissimilar 1.0.2 Diff#::Deleterust-analyzer cargo dissimilar 1.0.2 Diff#Delete#(range) => { |
| 440 | let adjust = boundary_downrust-analyzer cargo dissimilar 1.0.2 boundary_down().(range.docrust-analyzer cargo dissimilar 1.0.2 range/Range#doc., range.offsetrust-analyzer cargo dissimilar 1.0.2 range/Range#offset.); |
| 441 | range.offsetrust-analyzer cargo dissimilar 1.0.2 range/Range#offset. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().adjust; |
| 442 | range.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().adjust; |
| 443 | let adjust = boundary_uprust-analyzer cargo dissimilar 1.0.2 boundary_up().(range.docrust-analyzer cargo dissimilar 1.0.2 range/Range#doc., range.offsetrust-analyzer cargo dissimilar 1.0.2 range/Range#offset. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().range.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len.); |
| 444 | range.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().adjust; |
| 445 | } |
| 446 | Diffrust-analyzer cargo dissimilar 1.0.2 Diff#::Insertrust-analyzer cargo dissimilar 1.0.2 Diff#Insert#(range) => { |
| 447 | let adjust = boundary_downrust-analyzer cargo dissimilar 1.0.2 boundary_down().(range.docrust-analyzer cargo dissimilar 1.0.2 range/Range#doc., range.offsetrust-analyzer cargo dissimilar 1.0.2 range/Range#offset.); |
| 448 | range.offsetrust-analyzer cargo dissimilar 1.0.2 range/Range#offset. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().adjust; |
| 449 | range.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().adjust; |
| 450 | let adjust = boundary_uprust-analyzer cargo dissimilar 1.0.2 boundary_up().(range.docrust-analyzer cargo dissimilar 1.0.2 range/Range#doc., range.offsetrust-analyzer cargo dissimilar 1.0.2 range/Range#offset. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().range.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len.); |
| 451 | range.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().adjust; |
| 452 | } |
| 453 | } |
| 454 | } |
| 455 | |
| 456 | solution.utf8rust-analyzer cargo dissimilar 1.0.2 Solution#utf8. = true; |
| 457 | } |
| 458 | |
| 459 | // Reduce the number of edits by eliminating semantically trivial equalities. |
| 460 | fn cleanup_semanticrust-analyzer cargo dissimilar 1.0.2 cleanup_semantic().(solution: &mut Solutionrust-analyzer cargo dissimilar 1.0.2 Solution#) { |
| 461 | let mut diffs = &mut solution.diffsrust-analyzer cargo dissimilar 1.0.2 Solution#diffs.; |
| 462 | if diffs.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().() { |
| 463 | return; |
| 464 | } |
| 465 | |
| 466 | let mut changes = false; |
| 467 | let mut equalities = VecDequerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/VecDeque#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/impl#[`VecDeque<T>`]new().(); // Double-ended queue of equalities. |
| 468 | let mut last_equality = Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#; // Always equal to equalities.peek().text |
| 469 | let mut pointer = 0; |
| 470 | // Number of characters that changed prior to the equality. |
| 471 | let mut len_insertions1 = 0; |
| 472 | let mut len_deletions1 = 0; |
| 473 | // Number of characters that changed after the equality. |
| 474 | let mut len_insertions2 = 0; |
| 475 | let mut len_deletions2 = 0; |
| 476 | while let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&this_diff) = diffs.getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get().(pointer) { |
| 477 | match this_diff { |
| 478 | Diffrust-analyzer cargo dissimilar 1.0.2 Diff#::Equalrust-analyzer cargo dissimilar 1.0.2 Diff#Equal#(text1, text2) => { |
| 479 | equalities.push_backrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/impl#[`VecDeque<T, A>`]push_back().(pointer); |
| 480 | len_insertions1 = len_insertions2; |
| 481 | len_deletions1 = len_deletions2; |
| 482 | len_insertions2 = 0; |
| 483 | len_deletions2 = 0; |
| 484 | last_equality = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((text1, text2)); |
| 485 | pointer rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1; |
| 486 | continue; |
| 487 | } |
| 488 | Diffrust-analyzer cargo dissimilar 1.0.2 Diff#::Deleterust-analyzer cargo dissimilar 1.0.2 Diff#Delete#(text) => len_deletions2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().text.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len., |
| 489 | Diffrust-analyzer cargo dissimilar 1.0.2 Diff#::Insertrust-analyzer cargo dissimilar 1.0.2 Diff#Insert#(text) => len_insertions2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().text.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len., |
| 490 | } |
| 491 | // Eliminate an equality that is smaller or equal to the edits on both |
| 492 | // sides of it. |
| 493 | if last_equality.map_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map_or().(false, |(last_equality, _)| { |
| 494 | last_equality.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]le().cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/::maxrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/max().(len_insertions1, len_deletions1) |
| 495 | && last_equality.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]le().cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/::maxrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/max().(len_insertions2, len_deletions2) |
| 496 | }) { |
| 497 | // Jump back to offending equality. |
| 498 | pointer = equalities.pop_backrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/impl#[`VecDeque<T, A>`]pop_back().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 499 | |
| 500 | // Replace equality with a delete. |
| 501 | diffs[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut().pointer]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut(). = Diffrust-analyzer cargo dissimilar 1.0.2 Diff#::Deleterust-analyzer cargo dissimilar 1.0.2 Diff#Delete#(last_equality.unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().0); |
| 502 | // Insert a corresponding insert. |
| 503 | diffs.insertrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]insert().(pointer rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1, Diffrust-analyzer cargo dissimilar 1.0.2 Diff#::Insertrust-analyzer cargo dissimilar 1.0.2 Diff#Insert#(last_equality.unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().1)); |
| 504 | |
| 505 | len_insertions1 = 0; // Reset the counters. |
| 506 | len_insertions2 = 0; |
| 507 | len_deletions1 = 0; |
| 508 | len_deletions2 = 0; |
| 509 | last_equality = Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#; |
| 510 | changes = true; |
| 511 | |
| 512 | // Throw away the previous equality (it needs to be reevaluated). |
| 513 | equalities.pop_backrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/impl#[`VecDeque<T, A>`]pop_back().(); |
| 514 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(back) = equalities.backrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/impl#[`VecDeque<T, A>`]back().() { |
| 515 | // There is a safe equality we can fall back to. |
| 516 | pointer = *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().back; |
| 517 | } else { |
| 518 | // There are no previous equalities, jump back to the start. |
| 519 | pointer = 0; |
| 520 | continue; |
| 521 | } |
| 522 | } |
| 523 | pointer rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1; |
| 524 | } |
| 525 | |
| 526 | // Normalize the diff. |
| 527 | if changes { |
| 528 | cleanup_mergerust-analyzer cargo dissimilar 1.0.2 cleanup_merge().(solution); |
| 529 | } |
| 530 | cleanup_semantic_losslessrust-analyzer cargo dissimilar 1.0.2 cleanup_semantic_lossless().(solution); |
| 531 | diffs = &mut solution.diffsrust-analyzer cargo dissimilar 1.0.2 Solution#diffs.; |
| 532 | |
| 533 | // Find any overlaps between deletions and insertions. |
| 534 | // e.g: <del>abcxxx</del><ins>xxxdef</ins> |
| 535 | // -> <del>abc</del>xxx<ins>def</ins> |
| 536 | // e.g: <del>xxxabc</del><ins>defxxx</ins> |
| 537 | // -> <ins>def</ins>xxx<del>abc</del> |
| 538 | // Only extract an overlap if it is as big as the edit ahead or behind it. |
| 539 | let mut pointer = 1; |
| 540 | while let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&this_diff) = diffs.getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get().(pointer) { |
| 541 | let prev_diff = diffs[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().pointer rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().1]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().; |
| 542 | if let (Diffrust-analyzer cargo dissimilar 1.0.2 Diff#::Deleterust-analyzer cargo dissimilar 1.0.2 Diff#Delete#(deletion), Diffrust-analyzer cargo dissimilar 1.0.2 Diff#::Insertrust-analyzer cargo dissimilar 1.0.2 Diff#Insert#(insertion)) = (prev_diff, this_diff) { |
| 543 | let overlap_len1 = common_overlaprust-analyzer cargo dissimilar 1.0.2 common_overlap().(deletion, insertion); |
| 544 | let overlap_len2 = common_overlaprust-analyzer cargo dissimilar 1.0.2 common_overlap().(insertion, deletion); |
| 545 | let overlap_min = cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/::minrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/min().(deletion.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len., insertion.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len.); |
| 546 | if overlap_len1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().overlap_len2 && 2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().overlap_len1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().overlap_min { |
| 547 | // Overlap found. Insert an equality and trim the surrounding edits. |
| 548 | diffs.insertrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]insert().( |
| 549 | pointer, |
| 550 | Diffrust-analyzer cargo dissimilar 1.0.2 Diff#::Equalrust-analyzer cargo dissimilar 1.0.2 Diff#Equal#( |
| 551 | deletion.substringrust-analyzer cargo dissimilar 1.0.2 range/impl#[`Range<'a>`]substring().(deletion.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().overlap_len1..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#deletion.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len.), |
| 552 | insertion.substringrust-analyzer cargo dissimilar 1.0.2 range/impl#[`Range<'a>`]substring().(..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#overlap_len1), |
| 553 | ), |
| 554 | ); |
| 555 | diffs[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut().pointer rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().1]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut(). = |
| 556 | Diffrust-analyzer cargo dissimilar 1.0.2 Diff#::Deleterust-analyzer cargo dissimilar 1.0.2 Diff#Delete#(deletion.substringrust-analyzer cargo dissimilar 1.0.2 range/impl#[`Range<'a>`]substring().(..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#deletion.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().overlap_len1)); |
| 557 | diffs[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut().pointer rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut(). = Diffrust-analyzer cargo dissimilar 1.0.2 Diff#::Insertrust-analyzer cargo dissimilar 1.0.2 Diff#Insert#(insertion.substringrust-analyzer cargo dissimilar 1.0.2 range/impl#[`Range<'a>`]substring().(overlap_len1..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#)); |
| 558 | } else if overlap_len1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().overlap_len2 && 2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().overlap_len2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().overlap_min { |
| 559 | // Reverse overlap found. |
| 560 | // Insert an equality and swap and trim the surrounding edits. |
| 561 | diffs.insertrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]insert().( |
| 562 | pointer, |
| 563 | Diffrust-analyzer cargo dissimilar 1.0.2 Diff#::Equalrust-analyzer cargo dissimilar 1.0.2 Diff#Equal#( |
| 564 | deletion.substringrust-analyzer cargo dissimilar 1.0.2 range/impl#[`Range<'a>`]substring().(..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#overlap_len2), |
| 565 | insertion.substringrust-analyzer cargo dissimilar 1.0.2 range/impl#[`Range<'a>`]substring().(insertion.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().overlap_len2..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#insertion.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len.), |
| 566 | ), |
| 567 | ); |
| 568 | diffs[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut().pointer rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().1]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut(). = |
| 569 | Diffrust-analyzer cargo dissimilar 1.0.2 Diff#::Insertrust-analyzer cargo dissimilar 1.0.2 Diff#Insert#(insertion.substringrust-analyzer cargo dissimilar 1.0.2 range/impl#[`Range<'a>`]substring().(..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#insertion.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().overlap_len2)); |
| 570 | diffs[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut().pointer rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut(). = Diffrust-analyzer cargo dissimilar 1.0.2 Diff#::Deleterust-analyzer cargo dissimilar 1.0.2 Diff#Delete#(deletion.substringrust-analyzer cargo dissimilar 1.0.2 range/impl#[`Range<'a>`]substring().(overlap_len2..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#)); |
| 571 | } |
| 572 | pointer rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1; |
| 573 | } |
| 574 | pointer rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1; |
| 575 | } |
| 576 | } |
| 577 | |
| 578 | // Look for single edits surrounded on both sides by equalities which can be |
| 579 | // shifted sideways to align the edit to a word boundary. |
| 580 | // |
| 581 | // e.g: The c<ins>at c</ins>ame. -> The <ins>cat </ins>came. |
| 582 | fn cleanup_semantic_losslessrust-analyzer cargo dissimilar 1.0.2 cleanup_semantic_lossless().(solution: &mut Solutionrust-analyzer cargo dissimilar 1.0.2 Solution#) { |
| 583 | let diffs = &mut solution.diffsrust-analyzer cargo dissimilar 1.0.2 Solution#diffs.; |
| 584 | let mut pointer = 1; |
| 585 | while let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&next_diff) = diffs.getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get().(pointer rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1) { |
| 586 | let prev_diff = diffs[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().pointer rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().1]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().; |
| 587 | if let ( |
| 588 | Diffrust-analyzer cargo dissimilar 1.0.2 Diff#::Equalrust-analyzer cargo dissimilar 1.0.2 Diff#Equal#(mut prev_equal1, mut prev_equal2), |
| 589 | Diffrust-analyzer cargo dissimilar 1.0.2 Diff#::Equalrust-analyzer cargo dissimilar 1.0.2 Diff#Equal#(mut next_equal1, mut next_equal2), |
| 590 | ) = (prev_diff, next_diff) |
| 591 | { |
| 592 | // This is a single edit surrounded by equalities. |
| 593 | let mut edit = diffs[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().pointer]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().; |
| 594 | |
| 595 | // First, shift the edit as far left as possible. |
| 596 | let common_offset = common_suffixrust-analyzer cargo dissimilar 1.0.2 common_suffix().(prev_equal1, edit.textrust-analyzer cargo dissimilar 1.0.2 impl#[`Diff<'a, 'b>`]text().()); |
| 597 | let original_prev_len = prev_equal1.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len.; |
| 598 | prev_equal1.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().common_offset; |
| 599 | prev_equal2.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().common_offset; |
| 600 | edit.shift_leftrust-analyzer cargo dissimilar 1.0.2 impl#[`Diff<'a, 'b>`]shift_left().(common_offset); |
| 601 | next_equal1.offsetrust-analyzer cargo dissimilar 1.0.2 range/Range#offset. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().common_offset; |
| 602 | next_equal1.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().common_offset; |
| 603 | next_equal2.offsetrust-analyzer cargo dissimilar 1.0.2 range/Range#offset. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().common_offset; |
| 604 | next_equal2.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().common_offset; |
| 605 | |
| 606 | // Second, step character by character right, looking for the best fit. |
| 607 | let mut best_prev_equal = (prev_equal1, prev_equal2); |
| 608 | let mut best_edit = edit; |
| 609 | let mut best_next_equal = (next_equal1, next_equal2); |
| 610 | let mut best_score = cleanup_semantic_scorerust-analyzer cargo dissimilar 1.0.2 cleanup_semantic_score().(prev_equal1, edit.textrust-analyzer cargo dissimilar 1.0.2 impl#[`Diff<'a, 'b>`]text().()) |
| 611 | +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().cleanup_semantic_scorerust-analyzer cargo dissimilar 1.0.2 cleanup_semantic_score().(edit.textrust-analyzer cargo dissimilar 1.0.2 impl#[`Diff<'a, 'b>`]text().(), next_equal1); |
| 612 | while !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().edit.textrust-analyzer cargo dissimilar 1.0.2 impl#[`Diff<'a, 'b>`]text().().is_emptyrust-analyzer cargo dissimilar 1.0.2 range/impl#[`Range<'a>`]is_empty().() |
| 613 | && !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().next_equal1.is_emptyrust-analyzer cargo dissimilar 1.0.2 range/impl#[`Range<'a>`]is_empty().() |
| 614 | && edit.textrust-analyzer cargo dissimilar 1.0.2 impl#[`Diff<'a, 'b>`]text().().charsrust-analyzer cargo dissimilar 1.0.2 range/impl#[`Range<'a>`]chars().().nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/impl#[`Chars<'a>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().next_equal1.charsrust-analyzer cargo dissimilar 1.0.2 range/impl#[`Range<'a>`]chars().().nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/impl#[`Chars<'a>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().() |
| 615 | { |
| 616 | let increment = edit.textrust-analyzer cargo dissimilar 1.0.2 impl#[`Diff<'a, 'b>`]text().().charsrust-analyzer cargo dissimilar 1.0.2 range/impl#[`Range<'a>`]chars().().nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/impl#[`Chars<'a>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().len_utf8rust-analyzer cargo core https://github.com/rust-lang/rust/library/core char/methods/impl#[char]len_utf8().(); |
| 617 | prev_equal1.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().increment; |
| 618 | prev_equal2.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().increment; |
| 619 | edit.shift_rightrust-analyzer cargo dissimilar 1.0.2 impl#[`Diff<'a, 'b>`]shift_right().(increment); |
| 620 | next_equal1.offsetrust-analyzer cargo dissimilar 1.0.2 range/Range#offset. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().increment; |
| 621 | next_equal1.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().increment; |
| 622 | next_equal2.offsetrust-analyzer cargo dissimilar 1.0.2 range/Range#offset. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().increment; |
| 623 | next_equal2.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().increment; |
| 624 | let score = cleanup_semantic_scorerust-analyzer cargo dissimilar 1.0.2 cleanup_semantic_score().(prev_equal1, edit.textrust-analyzer cargo dissimilar 1.0.2 impl#[`Diff<'a, 'b>`]text().()) |
| 625 | +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().cleanup_semantic_scorerust-analyzer cargo dissimilar 1.0.2 cleanup_semantic_score().(edit.textrust-analyzer cargo dissimilar 1.0.2 impl#[`Diff<'a, 'b>`]text().(), next_equal1); |
| 626 | // The >= encourages trailing rather than leading whitespace on edits. |
| 627 | if score rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().best_score { |
| 628 | best_score = score; |
| 629 | best_prev_equal = (prev_equal1, prev_equal2); |
| 630 | best_edit = edit; |
| 631 | best_next_equal = (next_equal1, next_equal2); |
| 632 | } |
| 633 | } |
| 634 | |
| 635 | if original_prev_len rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().best_prev_equal.0.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len. { |
| 636 | // We have an improvement, save it back to the diff. |
| 637 | if best_next_equal.0.is_emptyrust-analyzer cargo dissimilar 1.0.2 range/impl#[`Range<'a>`]is_empty().() { |
| 638 | diffs.removerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]remove().(pointer rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1); |
| 639 | } else { |
| 640 | diffs[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut().pointer rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut(). = Diffrust-analyzer cargo dissimilar 1.0.2 Diff#::Equalrust-analyzer cargo dissimilar 1.0.2 Diff#Equal#(best_next_equal.0, best_next_equal.1); |
| 641 | } |
| 642 | diffs[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut().pointer]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut(). = best_edit; |
| 643 | if best_prev_equal.0.is_emptyrust-analyzer cargo dissimilar 1.0.2 range/impl#[`Range<'a>`]is_empty().() { |
| 644 | diffs.removerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]remove().(pointer rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().1); |
| 645 | pointer rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().1; |
| 646 | } else { |
| 647 | diffs[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut().pointer rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().1]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut(). = Diffrust-analyzer cargo dissimilar 1.0.2 Diff#::Equalrust-analyzer cargo dissimilar 1.0.2 Diff#Equal#(best_prev_equal.0, best_prev_equal.1); |
| 648 | } |
| 649 | } |
| 650 | } |
| 651 | pointer rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1; |
| 652 | } |
| 653 | } |
| 654 | |
| 655 | // Given two strings, compute a score representing whether the internal boundary |
| 656 | // falls on logical boundaries. |
| 657 | // |
| 658 | // Scores range from 6 (best) to 0 (worst). |
| 659 | fn cleanup_semantic_scorerust-analyzer cargo dissimilar 1.0.2 cleanup_semantic_score().(one: Rangerust-analyzer cargo dissimilar 1.0.2 range/Range#, two: Rangerust-analyzer cargo dissimilar 1.0.2 range/Range#) -> usize { |
| 660 | if one.is_emptyrust-analyzer cargo dissimilar 1.0.2 range/impl#[`Range<'a>`]is_empty().() || two.is_emptyrust-analyzer cargo dissimilar 1.0.2 range/impl#[`Range<'a>`]is_empty().() { |
| 661 | // Edges are the best. |
| 662 | return 6; |
| 663 | } |
| 664 | |
| 665 | // Each port of this function behaves slightly differently due to subtle |
| 666 | // differences in each language's definition of things like 'whitespace'. |
| 667 | // Since this function's purpose is largely cosmetic, the choice has been |
| 668 | // made to use each language's native features rather than force total |
| 669 | // conformity. |
| 670 | let char1 = one.charsrust-analyzer cargo dissimilar 1.0.2 range/impl#[`Range<'a>`]chars().().next_backrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/impl#[`Chars<'a>`][DoubleEndedIterator]next_back().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 671 | let char2 = two.charsrust-analyzer cargo dissimilar 1.0.2 range/impl#[`Range<'a>`]chars().().nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/impl#[`Chars<'a>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 672 | let non_alphanumeric1 = !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().char1.is_ascii_alphanumericrust-analyzer cargo core https://github.com/rust-lang/rust/library/core char/methods/impl#[char]is_ascii_alphanumeric().(); |
| 673 | let non_alphanumeric2 = !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().char2.is_ascii_alphanumericrust-analyzer cargo core https://github.com/rust-lang/rust/library/core char/methods/impl#[char]is_ascii_alphanumeric().(); |
| 674 | let whitespace1 = non_alphanumeric1 && char1.is_ascii_whitespacerust-analyzer cargo core https://github.com/rust-lang/rust/library/core char/methods/impl#[char]is_ascii_whitespace().(); |
| 675 | let whitespace2 = non_alphanumeric2 && char2.is_ascii_whitespacerust-analyzer cargo core https://github.com/rust-lang/rust/library/core char/methods/impl#[char]is_ascii_whitespace().(); |
| 676 | let line_break1 = whitespace1 && char1.is_controlrust-analyzer cargo core https://github.com/rust-lang/rust/library/core char/methods/impl#[char]is_control().(); |
| 677 | let line_break2 = whitespace2 && char2.is_controlrust-analyzer cargo core https://github.com/rust-lang/rust/library/core char/methods/impl#[char]is_control().(); |
| 678 | let blank_line1 = line_break1 && (one.ends_withrust-analyzer cargo dissimilar 1.0.2 range/impl#[`Range<'a>`]ends_with().("\n\n") || one.ends_withrust-analyzer cargo dissimilar 1.0.2 range/impl#[`Range<'a>`]ends_with().("\n\r\n")); |
| 679 | let blank_line2 = line_break2 && (two.starts_withrust-analyzer cargo dissimilar 1.0.2 range/impl#[`Range<'a>`]starts_with().("\n\n") || two.starts_withrust-analyzer cargo dissimilar 1.0.2 range/impl#[`Range<'a>`]starts_with().("\r\n\r\n")); |
| 680 | |
| 681 | if blank_line1 || blank_line2 { |
| 682 | // Five points for blank lines. |
| 683 | 5 |
| 684 | } else if line_break1 || line_break2 { |
| 685 | // Four points for line breaks. |
| 686 | 4 |
| 687 | } else if non_alphanumeric1 && !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().whitespace1 && whitespace2 { |
| 688 | // Three points for end of sentences. |
| 689 | 3 |
| 690 | } else if whitespace1 || whitespace2 { |
| 691 | // Two points for whitespace. |
| 692 | 2 |
| 693 | } else if non_alphanumeric1 || non_alphanumeric2 { |
| 694 | // One point for non-alphanumeric. |
| 695 | 1 |
| 696 | } else { |
| 697 | 0 |
| 698 | } |
| 699 | } |
| 700 | |
| 701 | // Reorder and merge like edit sections. Merge equalities. Any edit section can |
| 702 | // move as long as it doesn't cross an equality. |
| 703 | fn cleanup_mergerust-analyzer cargo dissimilar 1.0.2 cleanup_merge().(solution: &mut Solutionrust-analyzer cargo dissimilar 1.0.2 Solution#) { |
| 704 | let diffs = &mut solution.diffsrust-analyzer cargo dissimilar 1.0.2 Solution#diffs.; |
| 705 | let common_prefix = if solution.utf8rust-analyzer cargo dissimilar 1.0.2 Solution#utf8. { |
| 706 | common_prefixrust-analyzer cargo dissimilar 1.0.2 common_prefix(). |
| 707 | } else { |
| 708 | common_prefix_bytesrust-analyzer cargo dissimilar 1.0.2 common_prefix_bytes(). |
| 709 | }; |
| 710 | let common_suffix = if solution.utf8rust-analyzer cargo dissimilar 1.0.2 Solution#utf8. { |
| 711 | common_suffixrust-analyzer cargo dissimilar 1.0.2 common_suffix(). |
| 712 | } else { |
| 713 | common_suffix_bytesrust-analyzer cargo dissimilar 1.0.2 common_suffix_bytes(). |
| 714 | }; |
| 715 | |
| 716 | loop { |
| 717 | if diffs.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().() { |
| 718 | return; |
| 719 | } |
| 720 | |
| 721 | diffs.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(Diffrust-analyzer cargo dissimilar 1.0.2 Diff#::Equalrust-analyzer cargo dissimilar 1.0.2 Diff#Equal#( |
| 722 | solution.text1rust-analyzer cargo dissimilar 1.0.2 Solution#text1..substringrust-analyzer cargo dissimilar 1.0.2 range/impl#[`Range<'a>`]substring().(solution.text1rust-analyzer cargo dissimilar 1.0.2 Solution#text1..lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#), |
| 723 | solution.text2rust-analyzer cargo dissimilar 1.0.2 Solution#text2..substringrust-analyzer cargo dissimilar 1.0.2 range/impl#[`Range<'a>`]substring().(solution.text2rust-analyzer cargo dissimilar 1.0.2 Solution#text2..lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#), |
| 724 | )); // Add a dummy entry at the end. |
| 725 | let mut pointer = 0; |
| 726 | let mut count_delete = 0; |
| 727 | let mut count_insert = 0; |
| 728 | let mut text_delete = Rangerust-analyzer cargo dissimilar 1.0.2 range/Range#::emptyrust-analyzer cargo dissimilar 1.0.2 range/impl#[`Range<'a>`]empty().(); |
| 729 | let mut text_insert = Rangerust-analyzer cargo dissimilar 1.0.2 range/Range#::emptyrust-analyzer cargo dissimilar 1.0.2 range/impl#[`Range<'a>`]empty().(); |
| 730 | while let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&this_diff) = diffs.getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get().(pointer) { |
| 731 | match this_diff { |
| 732 | Diffrust-analyzer cargo dissimilar 1.0.2 Diff#::Insertrust-analyzer cargo dissimilar 1.0.2 Diff#Insert#(text) => { |
| 733 | count_insert rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1; |
| 734 | if text_insert.is_emptyrust-analyzer cargo dissimilar 1.0.2 range/impl#[`Range<'a>`]is_empty().() { |
| 735 | text_insert = text; |
| 736 | } else { |
| 737 | text_insert.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().text.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len.; |
| 738 | } |
| 739 | } |
| 740 | Diffrust-analyzer cargo dissimilar 1.0.2 Diff#::Deleterust-analyzer cargo dissimilar 1.0.2 Diff#Delete#(text) => { |
| 741 | count_delete rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1; |
| 742 | if text_delete.is_emptyrust-analyzer cargo dissimilar 1.0.2 range/impl#[`Range<'a>`]is_empty().() { |
| 743 | text_delete = text; |
| 744 | } else { |
| 745 | text_delete.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().text.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len.; |
| 746 | } |
| 747 | } |
| 748 | Diffrust-analyzer cargo dissimilar 1.0.2 Diff#::Equalrust-analyzer cargo dissimilar 1.0.2 Diff#Equal#(text, _) => { |
| 749 | let count_both = count_delete rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().count_insert; |
| 750 | if count_both rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().1 { |
| 751 | let both_types = count_delete rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().0 && count_insert rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().0; |
| 752 | // Delete the offending records. |
| 753 | diffs.splicerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]splice().(pointer rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().count_both..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#pointer, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 754 | pointer rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().count_both; |
| 755 | if both_types { |
| 756 | // Factor out any common prefix. |
| 757 | let common_length = common_prefix(text_insert, text_delete); |
| 758 | if common_length rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().0 { |
| 759 | if pointer rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().0 { |
| 760 | match &mut diffs[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut().pointer rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().1]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut(). { |
| 761 | Diffrust-analyzer cargo dissimilar 1.0.2 Diff#::Equalrust-analyzer cargo dissimilar 1.0.2 Diff#Equal#(this_diff1, this_diff2) => { |
| 762 | this_diff1.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().common_length; |
| 763 | this_diff2.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().common_length; |
| 764 | } |
| 765 | _ => unreachablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/unreachable!!( |
| 766 | "previous diff should have been an equality" |
| 767 | ), |
| 768 | } |
| 769 | } else { |
| 770 | diffs.insertrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]insert().( |
| 771 | pointer, |
| 772 | Diffrust-analyzer cargo dissimilar 1.0.2 Diff#::Equalrust-analyzer cargo dissimilar 1.0.2 Diff#Equal#( |
| 773 | text_delete.substringrust-analyzer cargo dissimilar 1.0.2 range/impl#[`Range<'a>`]substring().(..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#common_length), |
| 774 | text_insert.substringrust-analyzer cargo dissimilar 1.0.2 range/impl#[`Range<'a>`]substring().(..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#common_length), |
| 775 | ), |
| 776 | ); |
| 777 | pointer rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1; |
| 778 | } |
| 779 | text_insert = text_insert.substringrust-analyzer cargo dissimilar 1.0.2 range/impl#[`Range<'a>`]substring().(common_length..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#); |
| 780 | text_delete = text_delete.substringrust-analyzer cargo dissimilar 1.0.2 range/impl#[`Range<'a>`]substring().(common_length..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#); |
| 781 | } |
| 782 | // Factor out any common suffix. |
| 783 | let common_length = common_suffix(text_insert, text_delete); |
| 784 | if common_length rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().0 { |
| 785 | diffs[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut().pointer]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut()..grow_leftrust-analyzer cargo dissimilar 1.0.2 impl#[`Diff<'a, 'b>`]grow_left().(common_length); |
| 786 | text_insert.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().common_length; |
| 787 | text_delete.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().common_length; |
| 788 | } |
| 789 | } |
| 790 | // Insert the merged records. |
| 791 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().text_delete.is_emptyrust-analyzer cargo dissimilar 1.0.2 range/impl#[`Range<'a>`]is_empty().() { |
| 792 | diffs.insertrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]insert().(pointer, Diffrust-analyzer cargo dissimilar 1.0.2 Diff#::Deleterust-analyzer cargo dissimilar 1.0.2 Diff#Delete#(text_delete)); |
| 793 | pointer rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1; |
| 794 | } |
| 795 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().text_insert.is_emptyrust-analyzer cargo dissimilar 1.0.2 range/impl#[`Range<'a>`]is_empty().() { |
| 796 | diffs.insertrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]insert().(pointer, Diffrust-analyzer cargo dissimilar 1.0.2 Diff#::Insertrust-analyzer cargo dissimilar 1.0.2 Diff#Insert#(text_insert)); |
| 797 | pointer rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1; |
| 798 | } |
| 799 | } else if pointer rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().0 { |
| 800 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Diffrust-analyzer cargo dissimilar 1.0.2 Diff#::Equalrust-analyzer cargo dissimilar 1.0.2 Diff#Equal#(prev_equal1, prev_equal2)) = |
| 801 | diffs.get_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get_mut().(pointer rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().1) |
| 802 | { |
| 803 | // Merge this equality with the previous one. |
| 804 | prev_equal1.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().text.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len.; |
| 805 | prev_equal2.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().text.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len.; |
| 806 | diffs.removerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]remove().(pointer); |
| 807 | pointer rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().1; |
| 808 | } |
| 809 | } |
| 810 | count_insert = 0; |
| 811 | count_delete = 0; |
| 812 | text_delete = Rangerust-analyzer cargo dissimilar 1.0.2 range/Range#::emptyrust-analyzer cargo dissimilar 1.0.2 range/impl#[`Range<'a>`]empty().(); |
| 813 | text_insert = Rangerust-analyzer cargo dissimilar 1.0.2 range/Range#::emptyrust-analyzer cargo dissimilar 1.0.2 range/impl#[`Range<'a>`]empty().(); |
| 814 | } |
| 815 | } |
| 816 | pointer rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1; |
| 817 | } |
| 818 | if diffs.lastrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]last().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().textrust-analyzer cargo dissimilar 1.0.2 impl#[`Diff<'a, 'b>`]text().().is_emptyrust-analyzer cargo dissimilar 1.0.2 range/impl#[`Range<'a>`]is_empty().() { |
| 819 | diffs.poprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]pop().(); // Remove the dummy entry at the end. |
| 820 | } |
| 821 | |
| 822 | // Second pass: look for single edits surrounded on both sides by equalities |
| 823 | // which can be shifted sideways to eliminate an equality. |
| 824 | // e.g: A<ins>BA</ins>C -> <ins>AB</ins>AC |
| 825 | let mut changes = false; |
| 826 | let mut pointer = 1; |
| 827 | // Intentionally ignore the first and last element (don't need checking). |
| 828 | while let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&next_diff) = diffs.getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get().(pointer rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1) { |
| 829 | let prev_diff = diffs[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().pointer rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().1]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().; |
| 830 | let this_diff = diffs[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().pointer]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().; |
| 831 | if let (Diffrust-analyzer cargo dissimilar 1.0.2 Diff#::Equalrust-analyzer cargo dissimilar 1.0.2 Diff#Equal#(prev_diff, _), Diffrust-analyzer cargo dissimilar 1.0.2 Diff#::Equalrust-analyzer cargo dissimilar 1.0.2 Diff#Equal#(next_diff, _)) = (prev_diff, next_diff) { |
| 832 | // This is a single edit surrounded by equalities. |
| 833 | if this_diff.textrust-analyzer cargo dissimilar 1.0.2 impl#[`Diff<'a, 'b>`]text().().ends_withrust-analyzer cargo dissimilar 1.0.2 range/impl#[`Range<'a>`]ends_with().(prev_diff) { |
| 834 | // Shift the edit over the previous equality. |
| 835 | diffs[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut().pointer]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut()..shift_leftrust-analyzer cargo dissimilar 1.0.2 impl#[`Diff<'a, 'b>`]shift_left().(prev_diff.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len.); |
| 836 | diffs[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut().pointer rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut()..grow_leftrust-analyzer cargo dissimilar 1.0.2 impl#[`Diff<'a, 'b>`]grow_left().(prev_diff.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len.); |
| 837 | diffs.removerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]remove().(pointer rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().1); // Delete prev_diff. |
| 838 | changes = true; |
| 839 | } else if this_diff.textrust-analyzer cargo dissimilar 1.0.2 impl#[`Diff<'a, 'b>`]text().().starts_withrust-analyzer cargo dissimilar 1.0.2 range/impl#[`Range<'a>`]starts_with().(next_diff) { |
| 840 | // Shift the edit over the next equality. |
| 841 | diffs[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut().pointer rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().1]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut()..grow_rightrust-analyzer cargo dissimilar 1.0.2 impl#[`Diff<'a, 'b>`]grow_right().(next_diff.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len.); |
| 842 | diffs[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut().pointer]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut()..shift_rightrust-analyzer cargo dissimilar 1.0.2 impl#[`Diff<'a, 'b>`]shift_right().(next_diff.lenrust-analyzer cargo dissimilar 1.0.2 range/Range#len.); |
| 843 | diffs.removerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]remove().(pointer rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1); // Delete next_diff. |
| 844 | changes = true; |
| 845 | } |
| 846 | } |
| 847 | pointer rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1; |
| 848 | } |
| 849 | // If shifts were made, the diff needs reordering and another shift sweep. |
| 850 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().changes { |
| 851 | return; |
| 852 | } |
| 853 | } |
| 854 | } |
| 855 | |
| 856 | impl Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug# for Chunkrust-analyzer cargo dissimilar 1.0.2 Chunk#<'_> { |
| 857 | fn fmtrust-analyzer cargo dissimilar 1.0.2 impl#[`Chunk<'_>`][Debug]fmt().(&self, formatter: &mut fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#) -> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# { |
| 858 | let (name, text) = match *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self { |
| 859 | Chunkrust-analyzer cargo dissimilar 1.0.2 Chunk#::Equalrust-analyzer cargo dissimilar 1.0.2 Chunk#Equal#(text) => ("Equal", text), |
| 860 | Chunkrust-analyzer cargo dissimilar 1.0.2 Chunk#::Deleterust-analyzer cargo dissimilar 1.0.2 Chunk#Delete#(text) => ("Delete", text), |
| 861 | Chunkrust-analyzer cargo dissimilar 1.0.2 Chunk#::Insertrust-analyzer cargo dissimilar 1.0.2 Chunk#Insert#(text) => ("Insert", text), |
| 862 | }; |
| 863 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(formatter, "{}({:?})", name, text) |
| 864 | } |
| 865 | } |
| 866 | |
| 867 | impl Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug# for Diffrust-analyzer cargo dissimilar 1.0.2 Diff#<'_, '_> { |
| 868 | fn fmtrust-analyzer cargo dissimilar 1.0.2 impl#[`Diff<'_, '_>`][Debug]fmt().(&self, formatter: &mut fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#) -> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# { |
| 869 | let (name, bytes) = match *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self { |
| 870 | Diffrust-analyzer cargo dissimilar 1.0.2 Diff#::Equalrust-analyzer cargo dissimilar 1.0.2 Diff#Equal#(range, _) => ("Equal", bytesrust-analyzer cargo dissimilar 1.0.2 range/bytes().(range)), |
| 871 | Diffrust-analyzer cargo dissimilar 1.0.2 Diff#::Deleterust-analyzer cargo dissimilar 1.0.2 Diff#Delete#(range) => ("Delete", bytesrust-analyzer cargo dissimilar 1.0.2 range/bytes().(range)), |
| 872 | Diffrust-analyzer cargo dissimilar 1.0.2 Diff#::Insertrust-analyzer cargo dissimilar 1.0.2 Diff#Insert#(range) => ("Insert", bytesrust-analyzer cargo dissimilar 1.0.2 range/bytes().(range)), |
| 873 | }; |
| 874 | let text = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::from_utf8_lossyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]from_utf8_lossy().(bytes); |
| 875 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(formatter, "{}({:?})", name, text) |
| 876 | } |
| 877 | } |
| 878 | |
| 879 | impl<'a> Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<Diffrust-analyzer cargo dissimilar 1.0.2 Diff#<'a, 'a>> for Chunkrust-analyzer cargo dissimilar 1.0.2 Chunk#<'a> { |
| 880 | fn fromrust-analyzer cargo dissimilar 1.0.2 impl#[`Chunk<'a>`][`From<Diff<'a, 'a>>`]from().(diff: Diffrust-analyzer cargo dissimilar 1.0.2 Diff#<'a, 'a>) -> Selfrust-analyzer cargo dissimilar 1.0.2 impl#[`Chunk<'a>`][`From<Diff<'a, 'a>>`] { |
| 881 | match diff { |
| 882 | Diffrust-analyzer cargo dissimilar 1.0.2 Diff#::Equalrust-analyzer cargo dissimilar 1.0.2 Diff#Equal#(range, _) => Chunkrust-analyzer cargo dissimilar 1.0.2 Chunk#::Equalrust-analyzer cargo dissimilar 1.0.2 Chunk#Equal#(strrust-analyzer cargo dissimilar 1.0.2 range/str().(range)), |
| 883 | Diffrust-analyzer cargo dissimilar 1.0.2 Diff#::Deleterust-analyzer cargo dissimilar 1.0.2 Diff#Delete#(range) => Chunkrust-analyzer cargo dissimilar 1.0.2 Chunk#::Deleterust-analyzer cargo dissimilar 1.0.2 Chunk#Delete#(strrust-analyzer cargo dissimilar 1.0.2 range/str().(range)), |
| 884 | Diffrust-analyzer cargo dissimilar 1.0.2 Diff#::Insertrust-analyzer cargo dissimilar 1.0.2 Diff#Insert#(range) => Chunkrust-analyzer cargo dissimilar 1.0.2 Chunk#::Insertrust-analyzer cargo dissimilar 1.0.2 Chunk#Insert#(strrust-analyzer cargo dissimilar 1.0.2 range/str().(range)), |
| 885 | } |
| 886 | } |
| 887 | } |