diff options
author | Alan Donovan <adonovan@google.com> | 2022-07-04 13:22:21 -0400 |
---|---|---|
committer | Alan Donovan <adonovan@google.com> | 2022-07-07 16:57:02 +0000 |
commit | 1dfab61a4877c8b77d3b89afe7b36b74d3dba889 (patch) | |
tree | 7ce4eab0f8b8e25e9271cf7855b2880bd5c87c01 /internal/lsp/cache/maps.go | |
parent | 2aef121b8361efd5b8d56dd25a1ec046c50a4e01 (diff) | |
download | golang-x-tools-1dfab61a4877c8b77d3b89afe7b36b74d3dba889.tar.gz |
internal/lsp/cache: use GetHandle not Bind for 5 URI-keyed maps
This change replaces the 5 remaining calls to Bind (generational
lifetime) with GetHandle (reference counting). The handles
are now stored in persistent.Maps, which simplifies the
invalidation logic.
All 5 have span.URIs as keys:
symbolizeHandles
parse{Mod,Work}Handles
mod{Tidy,Why}Handles
Also, factor the functions that use these maps to have a common form:
- a fooImpl function that returns an R result and an error;
- a foo wrapper that decorates it with caching.
- a local fooResult type, defined struct{R; error} that is the cache entry.
The functions for getting/setting map entries are all inlined.
The fooHandle types are all replaced by *memoize.Handle, now that
their use is local.
No behavior change is intended.
The other uses of Bind are deleted in these CLs:
https://go-review.googlesource.com/c/tools/+/415975 (astCacheData)
https://go-review.googlesource.com/c/tools/+/415504 (actions)
Change-Id: I77cc4e828936fe171152ca13a12f7a639299e9e5
Reviewed-on: https://go-review.googlesource.com/c/tools/+/415976
Auto-Submit: Alan Donovan <adonovan@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Diffstat (limited to 'internal/lsp/cache/maps.go')
-rw-r--r-- | internal/lsp/cache/maps.go | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/internal/lsp/cache/maps.go b/internal/lsp/cache/maps.go index f8e03057c..1ec341515 100644 --- a/internal/lsp/cache/maps.go +++ b/internal/lsp/cache/maps.go @@ -16,11 +16,14 @@ type filesMap struct { impl *persistent.Map } +// uriLessInterface is the < relation for "any" values containing span.URIs. +func uriLessInterface(a, b interface{}) bool { + return a.(span.URI) < b.(span.URI) +} + func newFilesMap() filesMap { return filesMap{ - impl: persistent.NewMap(func(a, b interface{}) bool { - return a.(span.URI) < b.(span.URI) - }), + impl: persistent.NewMap(uriLessInterface), } } @@ -152,9 +155,7 @@ type parseKeysByURIMap struct { func newParseKeysByURIMap() parseKeysByURIMap { return parseKeysByURIMap{ - impl: persistent.NewMap(func(a, b interface{}) bool { - return a.(span.URI) < b.(span.URI) - }), + impl: persistent.NewMap(uriLessInterface), } } |