@@ -234,17 +234,16 @@ func (dmp *DiffMatchPatch) DiffMain(text1 string, text2 string, opt ...interface
234
234
// Trim off common suffix (speedup).
235
235
commonlength = dmp .DiffCommonSuffix (text1 , text2 )
236
236
commonsuffix := text1 [len (text1 )- commonlength :]
237
-
238
237
text1 = text1 [:len (text1 )- commonlength ]
239
238
text2 = text2 [:len (text2 )- commonlength ]
240
239
241
240
// Compute the diff on the middle block.
242
241
diffs = dmp .diffCompute (text1 , text2 , checklines , deadline )
242
+
243
243
// Restore the prefix and suffix.
244
244
if len (commonprefix ) != 0 {
245
245
diffs = append ([]Diff {Diff {DiffEqual , commonprefix }}, diffs ... )
246
246
}
247
-
248
247
if len (commonsuffix ) != 0 {
249
248
diffs = append (diffs , Diff {DiffEqual , commonsuffix })
250
249
}
@@ -259,15 +258,12 @@ func (dmp *DiffMatchPatch) diffCompute(text1 string, text2 string, checklines bo
259
258
if len (text1 ) == 0 {
260
259
// Just add some text (speedup).
261
260
return append (diffs , Diff {DiffInsert , text2 })
262
- }
263
-
264
- if len (text2 ) == 0 {
261
+ } else if len (text2 ) == 0 {
265
262
// Just delete some text (speedup).
266
263
return append (diffs , Diff {DiffDelete , text1 })
267
264
}
268
265
269
266
var longtext , shorttext string
270
-
271
267
if utf8 .RuneCountInString (text1 ) > utf8 .RuneCountInString (text2 ) {
272
268
longtext = text1
273
269
shorttext = text2
@@ -279,14 +275,14 @@ func (dmp *DiffMatchPatch) diffCompute(text1 string, text2 string, checklines bo
279
275
if i := strings .Index (longtext , shorttext ); i != - 1 {
280
276
var op int8 = DiffInsert
281
277
// Swap insertions for deletions if diff is reversed.
282
- if utf8 . RuneCountInString (text1 ) > utf8 . RuneCountInString (text2 ) {
278
+ if len (text1 ) > len (text2 ) {
283
279
op = DiffDelete
284
280
}
285
281
// Shorter text is inside the longer text (speedup).
286
282
diffs = []Diff {
287
- Diff {op , longtext [0 :i ]},
283
+ Diff {op , longtext [:i ]},
288
284
Diff {DiffEqual , shorttext },
289
- Diff {op , longtext [i + utf8 . RuneCountInString (shorttext ):]},
285
+ Diff {op , longtext [i + len (shorttext ):]},
290
286
}
291
287
292
288
return diffs
@@ -386,7 +382,7 @@ func (dmp *DiffMatchPatch) DiffBisect(text1 string, text2 string, deadline int64
386
382
s1 , s2 := []rune (text1 ), []rune (text2 )
387
383
s1_length , s2_length := len (s1 ), len (s2 )
388
384
389
- max_d := int ( math . Ceil ( float64 ((( s1_length + s2_length ) / 2 ))))
385
+ max_d := ( s1_length + s2_length + 1 ) / 2
390
386
v_offset := max_d
391
387
v_length := 2 * max_d
392
388
v1 := make ([]int , v_length )
@@ -413,7 +409,7 @@ func (dmp *DiffMatchPatch) DiffBisect(text1 string, text2 string, deadline int64
413
409
414
410
// Walk the front path one step.
415
411
for k1 := - d + k1start ; k1 <= d - k1end ; k1 += 2 {
416
- var k1_offset = v_offset + k1
412
+ k1_offset : = v_offset + k1
417
413
var x1 int
418
414
419
415
if k1 == - d || (k1 != d && v1 [k1_offset - 1 ] < v1 [k1_offset + 1 ]) {
@@ -680,16 +676,15 @@ func (dmp *DiffMatchPatch) DiffHalfMatch(text1, text2 string) []string {
680
676
shorttext = text1
681
677
}
682
678
683
- //TODO
684
679
if len (longtext ) < 4 || len (shorttext )* 2 < len (longtext ) {
685
680
return nil // Pointless.
686
681
}
687
682
688
683
// First check if the second quarter is the seed for a half-match.
689
- hm1 := dmp .diffHalfMatchI (longtext , shorttext , int (math . Ceil ( float64 (len (longtext )/ 4 )) ))
684
+ hm1 := dmp .diffHalfMatchI (longtext , shorttext , int (float64 (len (longtext )+ 3 ) / 4 ))
690
685
691
686
// Check again based on the third quarter.
692
- hm2 := dmp .diffHalfMatchI (longtext , shorttext , int (math . Ceil ( float64 (len (longtext )/ 2 )) ))
687
+ hm2 := dmp .diffHalfMatchI (longtext , shorttext , int (float64 (len (longtext )+ 1 ) / 2 ))
693
688
694
689
hm := []string {}
695
690
if hm1 == nil && hm2 == nil {
0 commit comments