]> Cypherpunks repositories - gostls13.git/commitdiff
all: use slices.Equal to simplify code
authorcuishuang <imcusg@gmail.com>
Mon, 31 Mar 2025 10:46:54 +0000 (18:46 +0800)
committerGopher Robot <gobot@golang.org>
Sun, 6 Apr 2025 16:36:41 +0000 (09:36 -0700)
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>
src/internal/syscall/windows/registry/registry_test.go
src/runtime/pprof/pprof_test.go

index 12eae54a8f381496e0713f1f323edad59cc3e85e..1e41d7d9f9f1dc48f259d3e1cdd9101f96931482 100644 (file)
@@ -10,6 +10,7 @@ import (
        "bytes"
        "crypto/rand"
        "os"
+       "slices"
        "syscall"
        "testing"
        "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     uint32
        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)
                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)
                return
        }
index 4b8f29c9181ddbc07def34eca858a723a939c067..5477d9ed26bd1f863c5bab427c4c611fc37a368a 100644 (file)
@@ -2558,15 +2558,7 @@ func TestProfilerStackDepth(t *testing.T) {
 }
 
 func hasPrefix(stk []string, prefix []string) bool {
-       if len(prefix) > len(stk) {
-               return false
-       }
-       for i := range prefix {
-               if stk[i] != prefix[i] {
-                       return false
-               }
-       }
-       return true
+       return len(prefix) <= len(stk) && slices.Equal(stk[:len(prefix)], prefix)
 }
 
 // ensure that stack records are valid map keys (comparable)