Skip to content

Commit 6fd9ee3

Browse files
cuishuanggopherbot
authored andcommitted
all: use slices.Equal to simplify code
Change-Id: Ib3be7cee6ca6dce899805aac176ca789eb2fd0f1 Reviewed-on: https://go-review.googlesource.com/c/go/+/661738 Reviewed-by: Carlos Amedee <[email protected]> Auto-Submit: Sean Liao <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Cherry Mui <[email protected]>
1 parent 1647896 commit 6fd9ee3

File tree

2 files changed

+3
-25
lines changed

2 files changed

+3
-25
lines changed

Diff for: src/internal/syscall/windows/registry/registry_test.go

+2-16
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"bytes"
1111
"crypto/rand"
1212
"os"
13+
"slices"
1314
"syscall"
1415
"testing"
1516
"unsafe"
@@ -100,21 +101,6 @@ func TestCreateOpenDeleteKey(t *testing.T) {
100101
}
101102
}
102103

103-
func equalStringSlice(a, b []string) bool {
104-
if len(a) != len(b) {
105-
return false
106-
}
107-
if a == nil {
108-
return true
109-
}
110-
for i := range a {
111-
if a[i] != b[i] {
112-
return false
113-
}
114-
}
115-
return true
116-
}
117-
118104
type ValueTest struct {
119105
Type uint32
120106
Name string
@@ -304,7 +290,7 @@ func testGetStringsValue(t *testing.T, k registry.Key, test ValueTest) {
304290
t.Errorf("GetStringsValue(%s) failed: %v", test.Name, err)
305291
return
306292
}
307-
if !equalStringSlice(got, test.Value.([]string)) {
293+
if !slices.Equal(got, test.Value.([]string)) {
308294
t.Errorf("want %s value %#v, got %#v", test.Name, test.Value, got)
309295
return
310296
}

Diff for: src/runtime/pprof/pprof_test.go

+1-9
Original file line numberDiff line numberDiff line change
@@ -2558,15 +2558,7 @@ func TestProfilerStackDepth(t *testing.T) {
25582558
}
25592559

25602560
func hasPrefix(stk []string, prefix []string) bool {
2561-
if len(prefix) > len(stk) {
2562-
return false
2563-
}
2564-
for i := range prefix {
2565-
if stk[i] != prefix[i] {
2566-
return false
2567-
}
2568-
}
2569-
return true
2561+
return len(prefix) <= len(stk) && slices.Equal(stk[:len(prefix)], prefix)
25702562
}
25712563

25722564
// ensure that stack records are valid map keys (comparable)

0 commit comments

Comments
 (0)