MCPcopy Create free account
hub / github.com/sergi/go-diff / commonSuffixLength

Function commonSuffixLength

diffmatchpatch/diff.go:445–457  ·  view source on GitHub ↗

commonSuffixLength returns the length of the common suffix of two rune slices.

(text1, text2 []rune)

Source from the content-addressed store, hash-verified

443
444// commonSuffixLength returns the length of the common suffix of two rune slices.
445func commonSuffixLength(text1, text2 []rune) int {
446 // Use linear search rather than the binary search discussed at https://neil.fraser.name/news/2007/10/09/.
447 // See discussion at https://github.com/sergi/go-diff/issues/54.
448 i1 := len(text1)
449 i2 := len(text2)
450 for n := 0; ; n++ {
451 i1--
452 i2--
453 if i1 < 0 || i2 < 0 || text1[i1] != text2[i2] {
454 return n
455 }
456 }
457}
458
459// DiffCommonOverlap determines if the suffix of one string is the prefix of another.
460func (dmp *DiffMatchPatch) DiffCommonOverlap(text1 string, text2 string) int {

Callers 6

diffMainRunesMethod · 0.85
DiffCommonSuffixMethod · 0.85
diffHalfMatchIMethod · 0.85
DiffCleanupMergeMethod · 0.85
BenchmarkCommonLengthFunction · 0.85
TestCommonSuffixLengthFunction · 0.85

Calls

no outgoing calls

Tested by 2

BenchmarkCommonLengthFunction · 0.68
TestCommonSuffixLengthFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…