Skip to content

Commit 6cf2633

Browse files
committed
Delete unused commonSuffixLength binary search code
See sergi#54 (comment) Closes sergi#54
1 parent 1744e29 commit 6cf2633

File tree

1 file changed

+3
-21
lines changed

1 file changed

+3
-21
lines changed

diffmatchpatch/diff.go

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,7 @@ func (dmp *DiffMatchPatch) DiffCommonSuffix(text1, text2 string) int {
434434

435435
// commonPrefixLength returns the length of the common prefix of two rune slices.
436436
func commonPrefixLength(text1, text2 []rune) int {
437+
// Linear search. See comment in commonSuffixLength.
437438
short, long := text1, text2
438439
if len(short) > len(long) {
439440
short, long = long, short
@@ -448,34 +449,15 @@ func commonPrefixLength(text1, text2 []rune) int {
448449

449450
// commonSuffixLength returns the length of the common suffix of two rune slices.
450451
func commonSuffixLength(text1, text2 []rune) int {
452+
// Use linear search rather than the binary search discussed at https://neil.fraser.name/news/2007/10/09/.
453+
// See discussion at https://github.com/sergi/go-diff/issues/54.
451454
n := min(len(text1), len(text2))
452455
for i := 0; i < n; i++ {
453456
if text1[len(text1)-i-1] != text2[len(text2)-i-1] {
454457
return i
455458
}
456459
}
457460
return n
458-
459-
// TODO research and benchmark this, why is it not activated? https://github.com/sergi/go-diff/issues/54
460-
// Binary search.
461-
// Performance analysis: http://neil.fraser.name/news/2007/10/09/
462-
/*
463-
pointermin := 0
464-
pointermax := math.Min(len(text1), len(text2))
465-
pointermid := pointermax
466-
pointerend := 0
467-
for pointermin < pointermid {
468-
if text1[len(text1)-pointermid:len(text1)-pointerend] ==
469-
text2[len(text2)-pointermid:len(text2)-pointerend] {
470-
pointermin = pointermid
471-
pointerend = pointermin
472-
} else {
473-
pointermax = pointermid
474-
}
475-
pointermid = math.Floor((pointermax-pointermin)/2 + pointermin)
476-
}
477-
return pointermid
478-
*/
479461
}
480462

481463
// DiffCommonOverlap determines if the suffix of one string is the prefix of another.

0 commit comments

Comments
 (0)