mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-07-04 01:07:49 +02:00
cmd/cli: use slices.Contains
This commit is contained in:
committed by
Cuong Manh Le
parent
7a491a4cc5
commit
ea4e5147bd
+2
-18
@@ -9,6 +9,7 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"net/netip"
|
"net/netip"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
@@ -285,8 +286,7 @@ func ignoringEINTR(fn func() error) error {
|
|||||||
func isSubSet(s1, s2 []string) bool {
|
func isSubSet(s1, s2 []string) bool {
|
||||||
ok := true
|
ok := true
|
||||||
for _, ns := range s1 {
|
for _, ns := range s1 {
|
||||||
// TODO(cuonglm): use slices.Contains once upgrading to go1.21
|
if slices.Contains(s2, ns) {
|
||||||
if sliceContains(s2, ns) {
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
ok = false
|
ok = false
|
||||||
@@ -294,19 +294,3 @@ func isSubSet(s1, s2 []string) bool {
|
|||||||
}
|
}
|
||||||
return ok
|
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
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user