Delete unused commonSuffixLength binary search code See https://github.com/sergi/go-diff/issues/54#issuecomment-343002957 Closes #54
diff --git a/diffmatchpatch/diff.go b/diffmatchpatch/diff.go index 82ad7bc..897ab67 100644 --- a/diffmatchpatch/diff.go +++ b/diffmatchpatch/diff.go
@@ -434,6 +434,7 @@ // commonPrefixLength returns the length of the common prefix of two rune slices. func commonPrefixLength(text1, text2 []rune) int { + // Linear search. See comment in commonSuffixLength. short, long := text1, text2 if len(short) > len(long) { short, long = long, short @@ -448,6 +449,8 @@ // commonSuffixLength returns the length of the common suffix of two rune slices. func commonSuffixLength(text1, text2 []rune) int { + // Use linear search rather than the binary search discussed at https://neil.fraser.name/news/2007/10/09/. + // See discussion at https://github.com/sergi/go-diff/issues/54. n := min(len(text1), len(text2)) for i := 0; i < n; i++ { if text1[len(text1)-i-1] != text2[len(text2)-i-1] { @@ -455,27 +458,6 @@ } } return n - - // TODO research and benchmark this, why is it not activated? https://github.com/sergi/go-diff/issues/54 - // Binary search. - // Performance analysis: http://neil.fraser.name/news/2007/10/09/ - /* - pointermin := 0 - pointermax := math.Min(len(text1), len(text2)) - pointermid := pointermax - pointerend := 0 - for pointermin < pointermid { - if text1[len(text1)-pointermid:len(text1)-pointerend] == - text2[len(text2)-pointermid:len(text2)-pointerend] { - pointermin = pointermid - pointerend = pointermin - } else { - pointermax = pointermid - } - pointermid = math.Floor((pointermax-pointermin)/2 + pointermin) - } - return pointermid - */ } // DiffCommonOverlap determines if the suffix of one string is the prefix of another.