mirror of https://github.com/golang/go.git
all: use slices.Contains to simplify code
Change-Id: I9ef075bbb0e3c65f3c2a9d49e599ef50b18aa9be Reviewed-on: https://go-review.googlesource.com/c/go/+/639535 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
This commit is contained in:
parent
3caf5bd09e
commit
39ceaf7961
|
|
@ -18,6 +18,7 @@ import (
|
|||
"reflect"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
|
@ -280,12 +281,7 @@ func (t *tester) shouldRunTest(name string) bool {
|
|||
if len(t.runNames) == 0 {
|
||||
return true
|
||||
}
|
||||
for _, runName := range t.runNames {
|
||||
if runName == name {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
return slices.Contains(t.runNames, name)
|
||||
}
|
||||
|
||||
func (t *tester) maybeLogMetadata() error {
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ import (
|
|||
"io"
|
||||
"io/fs"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"sort"
|
||||
"strings"
|
||||
"unicode"
|
||||
|
|
@ -887,23 +888,8 @@ func (ctxt *Context) matchTag(name string, allTags map[string]bool) bool {
|
|||
}
|
||||
|
||||
// other tags
|
||||
for _, tag := range ctxt.BuildTags {
|
||||
if tag == name {
|
||||
return true
|
||||
}
|
||||
}
|
||||
for _, tag := range ctxt.ToolTags {
|
||||
if tag == name {
|
||||
return true
|
||||
}
|
||||
}
|
||||
for _, tag := range ctxt.ReleaseTags {
|
||||
if tag == name {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
return slices.Contains(ctxt.BuildTags, name) || slices.Contains(ctxt.ToolTags, name) ||
|
||||
slices.Contains(ctxt.ReleaseTags, name)
|
||||
}
|
||||
|
||||
// goodOSArchFile returns false if the name contains a $GOOS or $GOARCH
|
||||
|
|
|
|||
|
|
@ -949,12 +949,7 @@ func (hs *serverHandshakeStateTLS13) shouldSendSessionTickets() bool {
|
|||
}
|
||||
|
||||
// Don't send tickets the client wouldn't use. See RFC 8446, Section 4.2.9.
|
||||
for _, pskMode := range hs.clientHello.pskModes {
|
||||
if pskMode == pskModeDHE {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
return slices.Contains(hs.clientHello.pskModes, pskModeDHE)
|
||||
}
|
||||
|
||||
func (hs *serverHandshakeStateTLS13) sendSessionTickets() error {
|
||||
|
|
|
|||
|
|
@ -1985,23 +1985,8 @@ func (ctxt *Context) matchTag(name string, allTags map[string]bool) bool {
|
|||
}
|
||||
|
||||
// other tags
|
||||
for _, tag := range ctxt.BuildTags {
|
||||
if tag == name {
|
||||
return true
|
||||
}
|
||||
}
|
||||
for _, tag := range ctxt.ToolTags {
|
||||
if tag == name {
|
||||
return true
|
||||
}
|
||||
}
|
||||
for _, tag := range ctxt.ReleaseTags {
|
||||
if tag == name {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
return slices.Contains(ctxt.BuildTags, name) || slices.Contains(ctxt.ToolTags, name) ||
|
||||
slices.Contains(ctxt.ReleaseTags, name)
|
||||
}
|
||||
|
||||
// goodOSArchFile returns false if the name contains a $GOOS or $GOARCH
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ import (
|
|||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"slices"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
|
|
@ -40,12 +41,7 @@ func newVisitor() visitor {
|
|||
return v
|
||||
}
|
||||
func (v visitor) filter(name string) bool {
|
||||
for _, typeName := range typeNames {
|
||||
if typeName == name {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
return slices.Contains(typeNames, name)
|
||||
}
|
||||
|
||||
func (v visitor) Visit(n ast.Node) ast.Visitor {
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ package trace
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"internal/trace/event"
|
||||
|
|
@ -1254,12 +1255,7 @@ func (s *rangeState) activeRange(typ rangeType, isInitialGen bool) error {
|
|||
|
||||
// hasRange returns true if a special time range on the goroutine as in progress.
|
||||
func (s *rangeState) hasRange(typ rangeType) bool {
|
||||
for _, ftyp := range s.inFlight {
|
||||
if ftyp == typ {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
return slices.Contains(s.inFlight, typ)
|
||||
}
|
||||
|
||||
// endRange ends a special range in time on the goroutine.
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ package user
|
|||
|
||||
import (
|
||||
"os"
|
||||
"slices"
|
||||
"testing"
|
||||
)
|
||||
|
||||
|
|
@ -178,16 +179,7 @@ func TestGroupIds(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatalf("%+v.GroupIds(): %v", user, err)
|
||||
}
|
||||
if !containsID(gids, user.Gid) {
|
||||
if !slices.Contains(gids, user.Gid) {
|
||||
t.Errorf("%+v.GroupIds() = %v; does not contain user GID %s", user, gids, user.Gid)
|
||||
}
|
||||
}
|
||||
|
||||
func containsID(ids []string, id string) bool {
|
||||
for _, x := range ids {
|
||||
if x == id {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ import (
|
|||
"os"
|
||||
"os/exec"
|
||||
"runtime"
|
||||
"slices"
|
||||
"strconv"
|
||||
"syscall"
|
||||
"testing"
|
||||
|
|
@ -205,7 +206,7 @@ func TestGroupIdsTestUser(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatalf("%+v.GroupIds(): %v", user, err)
|
||||
}
|
||||
if !containsID(gids, user.Gid) {
|
||||
if !slices.Contains(gids, user.Gid) {
|
||||
t.Errorf("%+v.GroupIds() = %v; does not contain user GID %s", user, gids, user.Gid)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ import (
|
|||
"internal/itoa"
|
||||
runtimesyscall "internal/runtime/syscall"
|
||||
"runtime"
|
||||
"slices"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
|
|
@ -134,12 +135,7 @@ func isGroupMember(gid int) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
for _, g := range groups {
|
||||
if g == gid {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
return slices.Contains(groups, gid)
|
||||
}
|
||||
|
||||
func isCapDacOverrideSet() bool {
|
||||
|
|
|
|||
Loading…
Reference in New Issue