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

Function commonPrefixLength

diffmatchpatch/diff.go:437–446  ·  view source on GitHub ↗

commonPrefixLength returns the length of the common prefix of two rune slices.

(text1, text2 []rune)

Source from the content-addressed store, hash-verified

435
436// commonPrefixLength returns the length of the common prefix of two rune slices.
437func commonPrefixLength(text1, text2 []rune) int {
438 // Linear search. See comment in commonSuffixLength.
439 n := 0
440 for ; n < len(text1) && n < len(text2); n++ {
441 if text1[n] != text2[n] {
442 return n
443 }
444 }
445 return n
446}
447
448// commonSuffixLength returns the length of the common suffix of two rune slices.
449func commonSuffixLength(text1, text2 []rune) int {

Callers 6

diffMainRunesMethod · 0.85
DiffCommonPrefixMethod · 0.85
diffHalfMatchIMethod · 0.85
DiffCleanupMergeMethod · 0.85
TestCommonPrefixLengthFunction · 0.85
BenchmarkCommonLengthFunction · 0.85

Calls

no outgoing calls

Tested by 2

TestCommonPrefixLengthFunction · 0.68
BenchmarkCommonLengthFunction · 0.68