aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2026-04-12 07:00:35 +0700
committerShulhan <ms@kilabit.info>2026-04-12 15:19:03 +0700
commit2d0135aace9468d40926bf94cdc88f579a3e9332 (patch)
tree9d03d390ffe77dfad9ab9c08fe0728da286da0f7
parentf9f699cd2bff3f9c6d84e597039f8bf694926792 (diff)
downloadpakakeh.go-2d0135aace9468d40926bf94cdc88f579a3e9332.tar.xz
text/diff: replace IsEqual with [bytes.Equal]
I cannot remember the use case for implementing IsEqual. Seems like the original purpose of IsEqual is to compare minimum length between two slices of bytes.
-rw-r--r--lib/text/diff/diff.go2
-rw-r--r--lib/text/diff/diffinterface.go32
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
}
}