@@ -245,18 +245,22 @@ func (dmp *DiffMatchPatch) DiffMain(text1, text2 string, checklines bool) []Diff
245
245
return dmp .diffMain (text1 , text2 , checklines , deadline )
246
246
}
247
247
248
- // DiffMain finds the differences between two rune sequences.
249
248
func (dmp * DiffMatchPatch ) diffMain (text1 , text2 string , checklines bool , deadline time.Time ) []Diff {
250
- diffs := []Diff {}
251
- if text1 == text2 {
252
- if len (text1 ) > 0 {
253
- diffs = append (diffs , Diff {DiffEqual , text1 })
254
- }
255
- return diffs
249
+ return dmp .diffMainRunes ([]rune (text1 ), []rune (text2 ), checklines , deadline )
250
+ }
251
+
252
+ // DiffMainRunes finds the differences between two rune sequences.
253
+ func (dmp * DiffMatchPatch ) DiffMainRunes (text1 , text2 []rune , checklines bool ) []Diff {
254
+ var deadline time.Time
255
+ if dmp .DiffTimeout <= 0 {
256
+ deadline = time .Now ().Add (24 * 365 * time .Hour )
257
+ } else {
258
+ deadline = time .Now ().Add (dmp .DiffTimeout )
256
259
}
257
- return dmp .diffMainRunes1 ([] rune ( text1 ), [] rune ( text2 ) , checklines , deadline )
260
+ return dmp .diffMainRunes ( text1 , text2 , checklines , deadline )
258
261
}
259
262
263
+
260
264
func (dmp * DiffMatchPatch ) diffMainRunes (text1 , text2 []rune , checklines bool , deadline time.Time ) []Diff {
261
265
if runesEqual (text1 , text2 ) {
262
266
var diffs []Diff
@@ -265,11 +269,6 @@ func (dmp *DiffMatchPatch) diffMainRunes(text1, text2 []rune, checklines bool, d
265
269
}
266
270
return diffs
267
271
}
268
- return dmp .diffMainRunes1 (text1 , text2 , checklines , deadline )
269
- }
270
-
271
-
272
- func (dmp * DiffMatchPatch ) diffMainRunes1 (text1 , text2 []rune , checklines bool , deadline time.Time ) []Diff {
273
272
// Trim off common prefix (speedup).
274
273
commonlength := commonPrefixLength (text1 , text2 )
275
274
commonprefix := text1 [:commonlength ]
@@ -418,9 +417,13 @@ func (dmp *DiffMatchPatch) diffLineMode(text1, text2 []rune, deadline time.Time)
418
417
// and return the recursively constructed diff.
419
418
// See Myers 1986 paper: An O(ND) Difference Algorithm and Its Variations.
420
419
func (dmp * DiffMatchPatch ) DiffBisect (text1 , text2 string , deadline time.Time ) []Diff {
420
+ // Unused in this code, but retained for interface compatibility.
421
421
return dmp .diffBisect ([]rune (text1 ), []rune (text2 ), deadline )
422
422
}
423
423
424
+ // diffBisect finds the 'middle snake' of a diff, splits the problem in two
425
+ // and returns the recursively constructed diff.
426
+ // See Myers's 1986 paper: An O(ND) Difference Algorithm and Its Variations.
424
427
func (dmp * DiffMatchPatch ) diffBisect (text1 , text2 []rune , deadline time.Time ) []Diff {
425
428
// Cache the text lengths to prevent multiple calls.
426
429
runes1_len , runes2_len := len (runes1 ), len (runes2 )
@@ -560,8 +563,7 @@ func (dmp *DiffMatchPatch) DiffLinesToChars(text1, text2 string) (string, string
560
563
return string (chars1 ), string (chars2 ), lineArray
561
564
}
562
565
563
- // DiffLinesToChars split two texts into a list of []runes. Reduces the texts to a string of
564
- // hashes where each Unicode character represents one line.
566
+ // DiffLinesToRunes splits two texts into a list of runes. Each rune represents one line.
565
567
func (dmp * DiffMatchPatch ) DiffLinesToRunes (text1 , text2 string ) ([]rune , []rune , []string ) {
566
568
// '\x00' is a valid character, but various debuggers don't like it.
567
569
// So we'll insert a junk entry to avoid generating a null character.
0 commit comments