Skip to content

Commit d58c5eb

Browse files
adonovangopherbot
authored andcommitted
gopls/internal/util/immutable: Map.Range -> Map.All, with iter.Seq2
Change-Id: I0e68ba3eb6fdcae9aa32098f6e8759ce5ac80141 Reviewed-on: https://go-review.googlesource.com/c/tools/+/684975 Auto-Submit: Alan Donovan <[email protected]> Reviewed-by: Robert Findley <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent 99387c8 commit d58c5eb

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

gopls/internal/cache/snapshot.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -967,9 +967,9 @@ func (s *Snapshot) WorkspaceMetadata(ctx context.Context) ([]*metadata.Package,
967967
defer s.mu.Unlock()
968968

969969
meta := make([]*metadata.Package, 0, s.workspacePackages.Len())
970-
s.workspacePackages.Range(func(id PackageID, _ PackagePath) {
970+
for id, _ := range s.workspacePackages.All() {
971971
meta = append(meta, s.meta.Packages[id])
972-
})
972+
}
973973
return meta, nil
974974
}
975975

gopls/internal/cache/source.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,9 @@ func (s *goplsSource) ResolveReferences(ctx context.Context, filename string, mi
110110

111111
dbgpr("fromWS", fromWS)
112112
dbgpr("old", old)
113-
s.S.workspacePackages.Range(func(k PackageID, v PackagePath) {
113+
for k, v := range s.S.workspacePackages.All() {
114114
log.Printf("workspacePackages[%s]=%s", k, v)
115-
})
115+
}
116116
// anything in ans with >1 matches?
117117
seen := make(map[string]int)
118118
for _, a := range fromWS {

gopls/internal/util/immutable/immutable.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88
// See the "persistent" package for copy-on-write data structures.
99
package immutable
1010

11+
import (
12+
"iter"
13+
"maps"
14+
)
15+
1116
// Map is an immutable wrapper around an ordinary Go map.
1217
type Map[K comparable, V any] struct {
1318
m map[K]V
@@ -33,11 +38,7 @@ func (m Map[K, V]) Len() int {
3338
return len(m.m)
3439
}
3540

36-
// Range calls f for each mapped (key, value) pair.
37-
// There is no way to break out of the loop.
38-
// TODO: generalize when Go iterators (#61405) land.
39-
func (m Map[K, V]) Range(f func(k K, v V)) {
40-
for k, v := range m.m {
41-
f(k, v)
42-
}
41+
// All returns an iterator over each mapped (key, value) pair.
42+
func (m Map[K, V]) All() iter.Seq2[K, V] {
43+
return maps.All(m.m)
4344
}

0 commit comments

Comments
 (0)