cmd/cli: use slices.Contains

This commit is contained in:
Cuong Manh Le
2024-03-21 18:27:07 +07:00
committed by Cuong Manh Le
parent 7a491a4cc5
commit ea4e5147bd

View File

@@ -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
}