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

Method diffMainRunes

diffmatchpatch/diff.go:98–130  ·  view source on GitHub ↗
(text1, text2 []rune, checklines bool, deadline time.Time)

Source from the content-addressed store, hash-verified

96}
97
98func (dmp *DiffMatchPatch) diffMainRunes(text1, text2 []rune, checklines bool, deadline time.Time) []Diff {
99 if runesEqual(text1, text2) {
100 var diffs []Diff
101 if len(text1) > 0 {
102 diffs = append(diffs, Diff{DiffEqual, string(text1)})
103 }
104 return diffs
105 }
106 // Trim off common prefix (speedup).
107 commonlength := commonPrefixLength(text1, text2)
108 commonprefix := text1[:commonlength]
109 text1 = text1[commonlength:]
110 text2 = text2[commonlength:]
111
112 // Trim off common suffix (speedup).
113 commonlength = commonSuffixLength(text1, text2)
114 commonsuffix := text1[len(text1)-commonlength:]
115 text1 = text1[:len(text1)-commonlength]
116 text2 = text2[:len(text2)-commonlength]
117
118 // Compute the diff on the middle block.
119 diffs := dmp.diffCompute(text1, text2, checklines, deadline)
120
121 // Restore the prefix and suffix.
122 if len(commonprefix) != 0 {
123 diffs = append([]Diff{{DiffEqual, string(commonprefix)}}, diffs...)
124 }
125 if len(commonsuffix) != 0 {
126 diffs = append(diffs, Diff{DiffEqual, string(commonsuffix)})
127 }
128
129 return dmp.DiffCleanupMerge(diffs)
130}
131
132// diffCompute finds the differences between two rune slices. Assumes that the texts do not have any common prefix or suffix.
133func (dmp *DiffMatchPatch) diffCompute(text1, text2 []rune, checklines bool, deadline time.Time) []Diff {

Callers 4

DiffMainRunesMethod · 0.95
diffComputeMethod · 0.95
diffLineModeMethod · 0.95
diffBisectSplitMethod · 0.95

Calls 5

diffComputeMethod · 0.95
DiffCleanupMergeMethod · 0.95
runesEqualFunction · 0.85
commonPrefixLengthFunction · 0.85
commonSuffixLengthFunction · 0.85

Tested by

no test coverage detected