@@ -290,8 +290,7 @@ func (dmp *DiffMatchPatch) diffCompute(text1 string, text2 string, checklines bo
290
290
shorttext = text1
291
291
}
292
292
293
- var i = strings .Index (longtext , shorttext )
294
- if i != - 1 {
293
+ if i := strings .Index (longtext , shorttext ); i != - 1 {
295
294
var op int8 = DiffInsert
296
295
// Swap insertions for deletions if diff is reversed.
297
296
if utf8 .RuneCountInString (text1 ) > utf8 .RuneCountInString (text2 ) {
@@ -305,18 +304,15 @@ func (dmp *DiffMatchPatch) diffCompute(text1 string, text2 string, checklines bo
305
304
}
306
305
307
306
return diffs
308
- }
309
- if utf8 .RuneCountInString (shorttext ) == 1 {
307
+ } else if utf8 .RuneCountInString (shorttext ) == 1 {
310
308
// Single character string.
311
309
// After the previous speedup, the character can't be an equality.
312
310
return []Diff {
313
311
Diff {DiffDelete , text1 },
314
312
Diff {DiffInsert , text2 },
315
313
}
316
- }
317
314
// Check to see if the problem can be split in two.
318
- hm := dmp .DiffHalfMatch (text1 , text2 )
319
- if hm != nil {
315
+ } else if hm := dmp .DiffHalfMatch (text1 , text2 ); hm != nil {
320
316
// A half-match was found, sort out the return data.
321
317
text1_a := hm [0 ]
322
318
text1_b := hm [1 ]
@@ -328,8 +324,7 @@ func (dmp *DiffMatchPatch) diffCompute(text1 string, text2 string, checklines bo
328
324
diffs_b := dmp .DiffMain (text1_b , text2_b , checklines , deadline )
329
325
// Merge the results.
330
326
return append (diffs_a , append ([]Diff {Diff {DiffEqual , mid_common }}, diffs_b ... )... )
331
- }
332
- if checklines && utf8 .RuneCountInString (text1 ) > 100 && utf8 .RuneCountInString (text2 ) > 100 {
327
+ } else if checklines && utf8 .RuneCountInString (text1 ) > 100 && utf8 .RuneCountInString (text2 ) > 100 {
333
328
return dmp .diffLineMode (text1 , text2 , deadline )
334
329
}
335
330
return dmp .DiffBisect (text1 , text2 , deadline )
@@ -591,9 +586,16 @@ func (dmp *DiffMatchPatch) DiffCharsToLines(diffs []Diff, lineArray []string) []
591
586
return hydrated
592
587
}
593
588
589
+ func min (x , y int ) int {
590
+ if x < y {
591
+ return x
592
+ }
593
+ return y
594
+ }
595
+
594
596
// DiffCommonPrefix determines the common prefix length of two strings.
595
597
func (dmp * DiffMatchPatch ) DiffCommonPrefix (text1 string , text2 string ) int {
596
- n := int ( math . Min ( float64 ( len (text1 )), float64 ( len (text2 )) ))
598
+ n := min ( len (text1 ), len (text2 ))
597
599
for i := 0 ; i < n ; i ++ {
598
600
if text1 [i ] != text2 [i ] {
599
601
return i
@@ -626,13 +628,13 @@ func (dmp *DiffMatchPatch) DiffCommonPrefix(text1 string, text2 string) int {
626
628
func (dmp * DiffMatchPatch ) DiffCommonSuffix (text1 string , text2 string ) int {
627
629
text1_length := len (text1 )
628
630
text2_length := len (text2 )
629
- n := math . Min ( float64 ( text1_length ), float64 ( text2_length ) )
630
- for i := 1 ; i <= int ( n ) ; i ++ {
631
+ n := min ( text1_length , text2_length )
632
+ for i := 1 ; i <= n ; i ++ {
631
633
if text1 [text1_length - i ] != text2 [text2_length - i ] {
632
634
return i - 1
633
635
}
634
636
}
635
- return int ( n )
637
+ return n
636
638
// Binary search.
637
639
// Performance analysis: http://neil.fraser.name/news/2007/10/09/
638
640
/*
0 commit comments