types/views: remove duplicate SliceContainsFunc

We already have `(Slice[T]).ContainsFunc`.

Updates #cleanup

Signed-off-by: Maisem Ali <maisem@tailscale.com>
pull/12004/head
Maisem Ali 6 months ago
parent 46980c9664
commit bf269b6c23

@ -3696,8 +3696,8 @@ func dnsConfigForNetmap(nm *netmap.NetworkMap, peers map[tailcfg.NodeID]tailcfg.
} }
// selfV6Only is whether we only have IPv6 addresses ourselves. // selfV6Only is whether we only have IPv6 addresses ourselves.
selfV6Only := views.SliceContainsFunc(nm.GetAddresses(), tsaddr.PrefixIs6) && selfV6Only := nm.GetAddresses().ContainsFunc(tsaddr.PrefixIs6) &&
!views.SliceContainsFunc(nm.GetAddresses(), tsaddr.PrefixIs4) !nm.GetAddresses().ContainsFunc(tsaddr.PrefixIs4)
dcfg.OnlyIPv6 = selfV6Only dcfg.OnlyIPv6 = selfV6Only
// Populate MagicDNS records. We do this unconditionally so that // Populate MagicDNS records. We do this unconditionally so that

@ -181,7 +181,7 @@ func NewContainsIPFunc(addrs views.Slice[netip.Prefix]) func(ip netip.Addr) bool
// If any addr is more than a single IP, then just do the slow // If any addr is more than a single IP, then just do the slow
// linear thing until // linear thing until
// https://github.com/inetaf/netaddr/issues/139 is done. // https://github.com/inetaf/netaddr/issues/139 is done.
if views.SliceContainsFunc(addrs, func(p netip.Prefix) bool { return !p.IsSingleIP() }) { if addrs.ContainsFunc(func(p netip.Prefix) bool { return !p.IsSingleIP() }) {
acopy := addrs.AsSlice() acopy := addrs.AsSlice()
return func(ip netip.Addr) bool { return func(ip netip.Addr) bool {
for _, a := range acopy { for _, a := range acopy {

@ -274,12 +274,7 @@ func (v Slice[T]) IndexFunc(f func(T) bool) int {
// //
// As it runs in O(n) time, use with care. // As it runs in O(n) time, use with care.
func (v Slice[T]) ContainsFunc(f func(T) bool) bool { func (v Slice[T]) ContainsFunc(f func(T) bool) bool {
for _, x := range v.ж { return slices.ContainsFunc(v.ж, f)
if f(x) {
return true
}
}
return false
} }
// SliceContains reports whether v contains element e. // SliceContains reports whether v contains element e.
@ -289,11 +284,6 @@ func SliceContains[T comparable](v Slice[T], e T) bool {
return slices.Contains(v.ж, e) return slices.Contains(v.ж, e)
} }
// SliceContainsFunc reports whether f reports true for any element in v.
func SliceContainsFunc[T any](v Slice[T], f func(T) bool) bool {
return slices.ContainsFunc(v.ж, f)
}
// SliceEqual is like the standard library's slices.Equal, but for two views. // SliceEqual is like the standard library's slices.Equal, but for two views.
func SliceEqual[T comparable](a, b Slice[T]) bool { func SliceEqual[T comparable](a, b Slice[T]) bool {
return slices.Equal(a.ж, b.ж) return slices.Equal(a.ж, b.ж)

@ -124,8 +124,6 @@ func TestViewUtils(t *testing.T) {
c.Check(v.IndexFunc(func(s string) bool { return strings.HasPrefix(s, "z") }), qt.Equals, -1) c.Check(v.IndexFunc(func(s string) bool { return strings.HasPrefix(s, "z") }), qt.Equals, -1)
c.Check(SliceContains(v, "bar"), qt.Equals, true) c.Check(SliceContains(v, "bar"), qt.Equals, true)
c.Check(SliceContains(v, "baz"), qt.Equals, false) c.Check(SliceContains(v, "baz"), qt.Equals, false)
c.Check(SliceContainsFunc(v, func(s string) bool { return strings.HasPrefix(s, "f") }), qt.Equals, true)
c.Check(SliceContainsFunc(v, func(s string) bool { return len(s) > 3 }), qt.Equals, false)
c.Check(SliceEqualAnyOrder(v, v), qt.Equals, true) c.Check(SliceEqualAnyOrder(v, v), qt.Equals, true)
c.Check(SliceEqualAnyOrder(v, SliceOf([]string{"bar", "foo"})), qt.Equals, true) c.Check(SliceEqualAnyOrder(v, SliceOf([]string{"bar", "foo"})), qt.Equals, true)
c.Check(SliceEqualAnyOrder(v, SliceOf([]string{"foo"})), qt.Equals, false) c.Check(SliceEqualAnyOrder(v, SliceOf([]string{"foo"})), qt.Equals, false)

Loading…
Cancel
Save