go/types/objectpath: add Encoder type, to amortize Scope.Names
This change adds a new Encoder type with For method, that
is functionally equivalent to the old For method but avoids
the surprising cost of repeated calls to Scope.Names, which
allocates and sorts a slice.
See golang/go#58668
Fixes golang/go#51017
Change-Id: I328e60c60f9bc312af253a0509aa029c41960d41
Reviewed-on: https://go-review.googlesource.com/c/tools/+/470678
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Tim King <taking@google.com>
Run-TryBot: Alan Donovan <adonovan@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
diff --git a/gopls/internal/lsp/source/methodsets/methodsets.go b/gopls/internal/lsp/source/methodsets/methodsets.go
index f8963b9..dac369b 100644
--- a/gopls/internal/lsp/source/methodsets/methodsets.go
+++ b/gopls/internal/lsp/source/methodsets/methodsets.go
@@ -57,7 +57,6 @@
"golang.org/x/tools/go/types/objectpath"
"golang.org/x/tools/gopls/internal/lsp/safetoken"
"golang.org/x/tools/internal/typeparams"
- "golang.org/x/tools/internal/typesinternal"
)
// An Index records the non-empty method sets of all package-level
@@ -232,7 +231,7 @@
return gobPosition{b.string(posn.Filename), posn.Offset, len(obj.Name())}
}
- objectpathFor := typesinternal.NewObjectpathFunc()
+ objectpathFor := new(objectpath.Encoder).For
// setindexInfo sets the (Posn, PkgPath, ObjectPath) fields for each method declaration.
setIndexInfo := func(m *gobMethod, method *types.Func) {