aboutsummaryrefslogtreecommitdiff
path: root/libgo/go/bytes
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2020-01-02 15:05:27 -0800
committerIan Lance Taylor <iant@golang.org>2020-01-21 23:53:22 -0800
commit5a8ea165926cb0737ab03bc48c18dc5198ab5305 (patch)
tree962dc3357c57f019f85658f99e2e753e30201c27 /libgo/go/bytes
parent6ac6529e155c9baa0aaaed7aca06bd38ebda5b43 (diff)
downloadgcc-5a8ea165926cb0737ab03bc48c18dc5198ab5305.zip
gcc-5a8ea165926cb0737ab03bc48c18dc5198ab5305.tar.gz
gcc-5a8ea165926cb0737ab03bc48c18dc5198ab5305.tar.bz2
libgo: update to Go1.14beta1
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/214297
Diffstat (limited to 'libgo/go/bytes')
-rw-r--r--libgo/go/bytes/bytes.go3
-rw-r--r--libgo/go/bytes/compare_test.go33
2 files changed, 35 insertions, 1 deletions
diff --git a/libgo/go/bytes/bytes.go b/libgo/go/bytes/bytes.go
index eb13212..e872cc2 100644
--- a/libgo/go/bytes/bytes.go
+++ b/libgo/go/bytes/bytes.go
@@ -935,7 +935,8 @@ func ReplaceAll(s, old, new []byte) []byte {
}
// EqualFold reports whether s and t, interpreted as UTF-8 strings,
-// are equal under Unicode case-folding.
+// are equal under Unicode case-folding, which is a more general
+// form of case-insensitivity.
func EqualFold(s, t []byte) bool {
for len(s) != 0 && len(t) != 0 {
// Extract first rune from each.
diff --git a/libgo/go/bytes/compare_test.go b/libgo/go/bytes/compare_test.go
index a321f2e..a595d57 100644
--- a/libgo/go/bytes/compare_test.go
+++ b/libgo/go/bytes/compare_test.go
@@ -120,6 +120,39 @@ func TestCompareBytes(t *testing.T) {
}
}
+func TestEndianBaseCompare(t *testing.T) {
+ // This test compares byte slices that are almost identical, except one
+ // difference that for some j, a[j]>b[j] and a[j+1]<b[j+1]. If the implementation
+ // compares large chunks with wrong endianness, it gets wrong result.
+ // no vector register is larger than 512 bytes for now
+ const maxLength = 512
+ a := make([]byte, maxLength)
+ b := make([]byte, maxLength)
+ // randomish but deterministic data. No 0 or 255.
+ for i := 0; i < maxLength; i++ {
+ a[i] = byte(1 + 31*i%254)
+ b[i] = byte(1 + 31*i%254)
+ }
+ for i := 2; i <= maxLength; i <<= 1 {
+ for j := 0; j < i-1; j++ {
+ a[j] = b[j] - 1
+ a[j+1] = b[j+1] + 1
+ cmp := Compare(a[:i], b[:i])
+ if cmp != -1 {
+ t.Errorf(`CompareBbigger(%d,%d) = %d`, i, j, cmp)
+ }
+ a[j] = b[j] + 1
+ a[j+1] = b[j+1] - 1
+ cmp = Compare(a[:i], b[:i])
+ if cmp != 1 {
+ t.Errorf(`CompareAbigger(%d,%d) = %d`, i, j, cmp)
+ }
+ a[j] = b[j]
+ a[j+1] = b[j+1]
+ }
+ }
+}
+
func BenchmarkCompareBytesEqual(b *testing.B) {
b1 := []byte("Hello Gophers!")
b2 := []byte("Hello Gophers!")