aboutsummaryrefslogtreecommitdiff
path: root/internal/lsp/cache/maps.go
diff options
context:
space:
mode:
authorAlan Donovan <adonovan@google.com>2022-07-01 17:28:48 -0400
committerGopher Robot <gobot@golang.org>2022-07-06 20:55:00 +0000
commit36430f4b355177a2580d8df0ec38bbf98556a14b (patch)
treec0f0d0313b0ce317fe8f15e31ce9ec59a2ea47ac /internal/lsp/cache/maps.go
parentb929f3bf4d57d9023b392ff552aa21a4845e1a07 (diff)
downloadgolang-x-tools-36430f4b355177a2580d8df0ec38bbf98556a14b.tar.gz
internal/lsp/cache: use GetHandle not Bind for actions
This change uses a persistent.Map for actions, just like packages. Actions are now reference counted rather than generational. Also: - note optimization opportunities. - minor cleanups. Change-Id: Ibbac8848a3beb3fe19056a7b160d2185155e7021 Reviewed-on: https://go-review.googlesource.com/c/tools/+/415504 gopls-CI: kokoro <noreply+kokoro@google.com> Auto-Submit: Alan Donovan <adonovan@google.com> Run-TryBot: Alan Donovan <adonovan@google.com> Reviewed-by: Robert Findley <rfindley@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
Diffstat (limited to 'internal/lsp/cache/maps.go')
-rw-r--r--internal/lsp/cache/maps.go24
1 files changed, 18 insertions, 6 deletions
diff --git a/internal/lsp/cache/maps.go b/internal/lsp/cache/maps.go
index af0417771..f8e03057c 100644
--- a/internal/lsp/cache/maps.go
+++ b/internal/lsp/cache/maps.go
@@ -197,16 +197,18 @@ type packagesMap struct {
func newPackagesMap() packagesMap {
return packagesMap{
impl: persistent.NewMap(func(a, b interface{}) bool {
- left := a.(packageKey)
- right := b.(packageKey)
- if left.mode != right.mode {
- return left.mode < right.mode
- }
- return left.id < right.id
+ return packageKeyLess(a.(packageKey), b.(packageKey))
}),
}
}
+func packageKeyLess(x, y packageKey) bool {
+ if x.mode != y.mode {
+ return x.mode < y.mode
+ }
+ return x.id < y.id
+}
+
func (m packagesMap) Clone() packagesMap {
return packagesMap{
impl: m.impl.Clone(),
@@ -285,3 +287,13 @@ func (s knownDirsSet) Insert(key span.URI) {
func (s knownDirsSet) Remove(key span.URI) {
s.impl.Delete(key)
}
+
+// actionKeyLessInterface is the less-than relation for actionKey
+// values wrapped in an interface.
+func actionKeyLessInterface(a, b interface{}) bool {
+ x, y := a.(actionKey), b.(actionKey)
+ if x.analyzer.Name != y.analyzer.Name {
+ return x.analyzer.Name < y.analyzer.Name
+ }
+ return packageKeyLess(x.pkg, y.pkg)
+}