]> Cypherpunks repositories - gostls13.git/commitdiff
runtime/pprof: use slices.Contains
authorTobias Klauser <tklauser@distanz.ch>
Thu, 12 Sep 2024 12:14:34 +0000 (14:14 +0200)
committerGopher Robot <gobot@golang.org>
Thu, 12 Sep 2024 14:50:13 +0000 (14:50 +0000)
Change-Id: I013aae68f47d7a37deb44097f80a213d8c7976bc
Reviewed-on: https://go-review.googlesource.com/c/go/+/612655
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

src/runtime/pprof/pprof_test.go

index 0b4e353bb12802706395b4dcca48fadaf35c44d2..6d03c6464b4176aa5778f84a074e51c42bcd284c 100644 (file)
@@ -21,6 +21,7 @@ import (
        "regexp"
        "runtime"
        "runtime/debug"
+       "slices"
        "strconv"
        "strings"
        "sync"
@@ -520,15 +521,6 @@ func diffCPUTime(t *testing.T, f func()) (user, system time.Duration) {
        return 0, 0
 }
 
-func contains(slice []string, s string) bool {
-       for i := range slice {
-               if slice[i] == s {
-                       return true
-               }
-       }
-       return false
-}
-
 // stackContains matches if a function named spec appears anywhere in the stack trace.
 func stackContains(spec string, count uintptr, stk []*profile.Location, labels map[string][]string) bool {
        for _, loc := range stk {
@@ -1877,7 +1869,7 @@ func stackContainsLabeled(spec string, count uintptr, stk []*profile.Location, l
        if !ok {
                panic("missing = in key/value spec")
        }
-       if !contains(labels[k], v) {
+       if !slices.Contains(labels[k], v) {
                return false
        }
        return stackContains(base, count, stk, labels)
@@ -1994,7 +1986,7 @@ func TestLabelSystemstack(t *testing.T) {
        // * labelHog should always be labeled.
        // * The label should _only_ appear on labelHog and the Do call above.
        for _, s := range p.Sample {
-               isLabeled := s.Label != nil && contains(s.Label["key"], "value")
+               isLabeled := s.Label != nil && slices.Contains(s.Label["key"], "value")
                var (
                        mayBeLabeled     bool
                        mustBeLabeled    string