mirror of
https://github.com/golang/go.git
synced 2025-05-05 15:43:04 +00:00
all: use slices.Equal to simplify code
Change-Id: Ib3be7cee6ca6dce899805aac176ca789eb2fd0f1 Reviewed-on: https://go-review.googlesource.com/c/go/+/661738 Reviewed-by: Carlos Amedee <carlos@golang.org> Auto-Submit: Sean Liao <sean@liao.dev> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
This commit is contained in:
parent
1647896aa2
commit
6fd9ee3da9
@ -10,6 +10,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"os"
|
"os"
|
||||||
|
"slices"
|
||||||
"syscall"
|
"syscall"
|
||||||
"testing"
|
"testing"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
@ -100,21 +101,6 @@ func TestCreateOpenDeleteKey(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func equalStringSlice(a, b []string) bool {
|
|
||||||
if len(a) != len(b) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
if a == nil {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
for i := range a {
|
|
||||||
if a[i] != b[i] {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
type ValueTest struct {
|
type ValueTest struct {
|
||||||
Type uint32
|
Type uint32
|
||||||
Name string
|
Name string
|
||||||
@ -304,7 +290,7 @@ func testGetStringsValue(t *testing.T, k registry.Key, test ValueTest) {
|
|||||||
t.Errorf("GetStringsValue(%s) failed: %v", test.Name, err)
|
t.Errorf("GetStringsValue(%s) failed: %v", test.Name, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if !equalStringSlice(got, test.Value.([]string)) {
|
if !slices.Equal(got, test.Value.([]string)) {
|
||||||
t.Errorf("want %s value %#v, got %#v", test.Name, test.Value, got)
|
t.Errorf("want %s value %#v, got %#v", test.Name, test.Value, got)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -2558,15 +2558,7 @@ func TestProfilerStackDepth(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func hasPrefix(stk []string, prefix []string) bool {
|
func hasPrefix(stk []string, prefix []string) bool {
|
||||||
if len(prefix) > len(stk) {
|
return len(prefix) <= len(stk) && slices.Equal(stk[:len(prefix)], prefix)
|
||||||
return false
|
|
||||||
}
|
|
||||||
for i := range prefix {
|
|
||||||
if stk[i] != prefix[i] {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ensure that stack records are valid map keys (comparable)
|
// ensure that stack records are valid map keys (comparable)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user