Skip to content

Commit

Permalink
Delete unused commonSuffixLength binary search code
Browse files Browse the repository at this point in the history
See #54 (comment)

Closes #54
  • Loading branch information
josharian committed Nov 13, 2017
1 parent 1744e29 commit 6cf2633
Showing 1 changed file with 3 additions and 21 deletions.
24 changes: 3 additions & 21 deletions diffmatchpatch/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@ func (dmp *DiffMatchPatch) DiffCommonSuffix(text1, text2 string) int {

// 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
Expand All @@ -448,34 +449,15 @@ func commonPrefixLength(text1, text2 []rune) int {

// 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] {
return i
}
}
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.
Expand Down

0 comments on commit 6cf2633

Please sign in to comment.