diff --git a/syncs/syncs.go b/syncs/syncs.go index bfb7c1e04..4496581a6 100644 --- a/syncs/syncs.go +++ b/syncs/syncs.go @@ -253,22 +253,6 @@ func (m *Map[K, V]) Delete(key K) { delete(m.m, key) } -// Range iterates over the map in an undefined order calling f for each entry. -// Iteration stops if f returns false. Map changes are blocked during iteration. -// A read lock is held for the entire duration of the iteration. -// Use the [WithLock] method instead to mutate the map during iteration. -// -// Deprecated: Use [All], [Keys], or [Values] instead. -func (m *Map[K, V]) Range(f func(key K, value V) bool) { - m.mu.RLock() - defer m.mu.RUnlock() - for k, v := range m.m { - if !f(k, v) { - return - } - } -} - // Keys iterates over all keys in the map in an undefined order. // A read lock is held for the entire duration of the iteration. // Use the [WithLock] method instead to mutate the map during iteration. diff --git a/syncs/syncs_test.go b/syncs/syncs_test.go index 0748dcb72..ee3711e76 100644 --- a/syncs/syncs_test.go +++ b/syncs/syncs_test.go @@ -160,10 +160,9 @@ func TestMap(t *testing.T) { } got := map[string]int{} want := map[string]int{"one": 1, "two": 2, "three": 3} - m.Range(func(k string, v int) bool { + for k, v := range m.All() { got[k] = v - return true - }) + } if d := cmp.Diff(got, want); d != "" { t.Errorf("Range mismatch (-got +want):\n%s", d) } @@ -178,10 +177,9 @@ func TestMap(t *testing.T) { m.Delete("noexist") got = map[string]int{} want = map[string]int{} - m.Range(func(k string, v int) bool { + for k, v := range m.All() { got[k] = v - return true - }) + } if d := cmp.Diff(got, want); d != "" { t.Errorf("Range mismatch (-got +want):\n%s", d) } diff --git a/taildrop/taildrop.go b/taildrop/taildrop.go index 9ad0e1a7e..e425027c5 100644 --- a/taildrop/taildrop.go +++ b/taildrop/taildrop.go @@ -226,7 +226,7 @@ func (m *Manager) IncomingFiles() []ipn.PartialFile { // in JSON to clients. They distinguish between empty and non-nil // to know whether a Notify should be able about files. files := make([]ipn.PartialFile, 0) - m.incomingFiles.Range(func(k incomingFileKey, f *incomingFile) bool { + for k, f := range m.incomingFiles.All() { f.mu.Lock() defer f.mu.Unlock() files = append(files, ipn.PartialFile{ @@ -238,8 +238,7 @@ func (m *Manager) IncomingFiles() []ipn.PartialFile { FinalPath: f.finalPath, Done: f.done, }) - return true - }) + } return files } diff --git a/tstest/natlab/vnet/vnet.go b/tstest/natlab/vnet/vnet.go index 919ae1fa1..e7991b3e6 100644 --- a/tstest/natlab/vnet/vnet.go +++ b/tstest/natlab/vnet/vnet.go @@ -974,13 +974,12 @@ func (n *network) writeEth(res []byte) bool { if dstMAC.IsBroadcast() || (n.v6 && etherType == layers.EthernetTypeIPv6 && dstMAC == macAllNodes) { num := 0 - n.writers.Range(func(mac MAC, nw networkWriter) bool { + for mac, nw := range n.writers.All() { if mac != srcMAC { num++ nw.write(res) } - return true - }) + } return num > 0 } if srcMAC == dstMAC { diff --git a/wgengine/netstack/netstack.go b/wgengine/netstack/netstack.go index efb328102..3185c5d55 100644 --- a/wgengine/netstack/netstack.go +++ b/wgengine/netstack/netstack.go @@ -414,15 +414,14 @@ func init() { // endpoint, and name collisions will result in Prometheus scraping errors. clientmetric.NewCounterFunc("netstack_tcp_forward_dropped_attempts", func() int64 { var total uint64 - stacksForMetrics.Range(func(ns *Impl, _ struct{}) bool { + for ns := range stacksForMetrics.Keys() { delta := ns.ipstack.Stats().TCP.ForwardMaxInFlightDrop.Value() if total+delta > math.MaxInt64 { total = math.MaxInt64 - return false + break } total += delta - return true - }) + } return int64(total) }) }