internal/imports: dedupe import paths for standard library packages
This change dedupes cached standard library packages too since we might
see some of them again while reading disk.
Fixes golang/go#41745
Change-Id: I879bfd9e199dffdde2d88438124154f164f64f00
Reviewed-on: https://go-review.googlesource.com/c/tools/+/261081
Run-TryBot: Danish Dua <danishdua@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Danish Dua <danishdua@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
diff --git a/internal/imports/fix.go b/internal/imports/fix.go
index 0bd91a8..7a8e93f 100644
--- a/internal/imports/fix.go
+++ b/internal/imports/fix.go
@@ -607,6 +607,10 @@
if err != nil {
return err
}
+
+ var mu sync.Mutex // to guard asynchronous access to dupCheck
+ dupCheck := map[string]struct{}{}
+
// Start off with the standard library.
for importPath, exports := range stdlib {
p := &pkg{
@@ -615,14 +619,12 @@
packageName: path.Base(importPath),
relevance: MaxRelevance,
}
+ dupCheck[importPath] = struct{}{}
if notSelf(p) && wrappedCallback.dirFound(p) && wrappedCallback.packageNameLoaded(p) {
wrappedCallback.exportsLoaded(p, exports)
}
}
- var mu sync.Mutex
- dupCheck := map[string]struct{}{}
-
scanFilter := &scanCallback{
rootFound: func(root gopathwalk.Root) bool {
// Exclude goroot results -- getting them is relatively expensive, not cached,