commonSuffixLength returns the length of the common suffix of two rune slices.
(text1, text2 []rune)
| 447 | |
| 448 | // commonSuffixLength returns the length of the common suffix of two rune slices. |
| 449 | func commonSuffixLength(text1, text2 []rune) int { |
| 450 | // Use linear search rather than the binary search discussed at https://neil.fraser.name/news/2007/10/09/. |
| 451 | // See discussion at https://github.com/sergi/go-diff/issues/54. |
| 452 | i1 := len(text1) |
| 453 | i2 := len(text2) |
| 454 | for n := 0; ; n++ { |
| 455 | i1-- |
| 456 | i2-- |
| 457 | if i1 < 0 || i2 < 0 || text1[i1] != text2[i2] { |
| 458 | return n |
| 459 | } |
| 460 | } |
| 461 | } |
| 462 | |
| 463 | // commonSuffixBytes returns the length in bytes of the common suffix of two strings, never splitting a rune. |
| 464 | func commonSuffixBytes(text1, text2 string) int { |
no outgoing calls