From ea4e5147bd516bb49663ee0ec237582c50beb840 Mon Sep 17 00:00:00 2001 From: Cuong Manh Le Date: Thu, 21 Mar 2024 18:27:07 +0700 Subject: [PATCH] cmd/cli: use slices.Contains --- cmd/cli/os_linux.go | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/cmd/cli/os_linux.go b/cmd/cli/os_linux.go index 89e9edb..a36311d 100644 --- a/cmd/cli/os_linux.go +++ b/cmd/cli/os_linux.go @@ -9,6 +9,7 @@ import ( "net" "net/netip" "os/exec" + "slices" "strings" "syscall" "time" @@ -285,8 +286,7 @@ func ignoringEINTR(fn func() error) error { func isSubSet(s1, s2 []string) bool { ok := true for _, ns := range s1 { - // TODO(cuonglm): use slices.Contains once upgrading to go1.21 - if sliceContains(s2, ns) { + if slices.Contains(s2, ns) { continue } ok = false @@ -294,19 +294,3 @@ func isSubSet(s1, s2 []string) bool { } return ok } - -// sliceContains reports whether v is present in s. -func sliceContains[S ~[]E, E comparable](s S, v E) bool { - return sliceIndex(s, v) >= 0 -} - -// sliceIndex returns the index of the first occurrence of v in s, -// or -1 if not present. -func sliceIndex[S ~[]E, E comparable](s S, v E) int { - for i := range s { - if v == s[i] { - return i - } - } - return -1 -}