diff options
| -rw-r--r-- | lib/text/diff/diff.go | 2 | ||||
| -rw-r--r-- | lib/text/diff/diffinterface.go | 32 |
2 files changed, 4 insertions, 30 deletions
diff --git a/lib/text/diff/diff.go b/lib/text/diff/diff.go index c587a829..8a8646fb 100644 --- a/lib/text/diff/diff.go +++ b/lib/text/diff/diff.go @@ -62,7 +62,7 @@ func Lines(oldlines, newlines []Line, level int) (diffs Data) { } // Compare old line with new line. - if IsEqual(oldlines[x].Val, newlines[y].Val) { + if bytes.Equal(oldlines[x].Val, newlines[y].Val) { oldlines[x].NumOther = newlines[y].Num newlines[y].NumOther = oldlines[x].Num x++ diff --git a/lib/text/diff/diffinterface.go b/lib/text/diff/diffinterface.go index 507d5b14..cff85b4a 100644 --- a/lib/text/diff/diffinterface.go +++ b/lib/text/diff/diffinterface.go @@ -4,6 +4,8 @@ package diff import ( + "bytes" + inbytes "git.sr.ht/~shulhan/pakakeh.go/internal/bytes" "git.sr.ht/~shulhan/pakakeh.go/lib/text" ) @@ -25,34 +27,6 @@ const ( DefMatchRatio = 0.7 ) -// IsEqual compare two slice of bytes and return true if equal or false -// otherwise. -func IsEqual(oldb, newb []byte) (equal bool) { - oldblen := len(oldb) - newblen := len(newb) - - // Do not compare the length, because we care about the index. - - minlen := 0 - switch { - case oldblen < newblen: - minlen = oldblen - case oldblen == newblen: - minlen = oldblen - default: - minlen = newblen - } - - at := 0 - for ; at < minlen; at++ { - if oldb[at] != newb[at] { - return - } - } - - return oldblen == newblen -} - // BytesRatio compare two slice of bytes and return ratio of matching bytes. // The ratio in in range of 0.0 to 1.0, where 1.0 if both are similar, and 0.0 // if no matchs even found. @@ -162,7 +136,7 @@ func findLine(line Line, text []Line, startat int) ( textlen := len(text) for n = startat; n < textlen; n++ { - if IsEqual(line.Val, text[n].Val) { + if bytes.Equal(line.Val, text[n].Val) { return true, n } } |
