From 4c644d7e323d3b4a3883d4e238b908fe615f7586 Mon Sep 17 00:00:00 2001 From: Rebecca Stambler Date: Mon, 1 Apr 2019 14:25:45 -0400 Subject: [PATCH] internal/lsp: avoid extra work in *cache.View.remove Fixes golang/go#31177 Change-Id: I31219c6285fecd0abc4ff5ec4ae732bcfcb69511 Reviewed-on: https://go-review.googlesource.com/c/tools/+/170182 Reviewed-by: Ian Cottrell Run-TryBot: Rebecca Stambler TryBot-Result: Gobot Gobot --- internal/lsp/cache/view.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/internal/lsp/cache/view.go b/internal/lsp/cache/view.go index 67bed47d..e6109a20 100644 --- a/internal/lsp/cache/view.go +++ b/internal/lsp/cache/view.go @@ -172,7 +172,7 @@ func (v *View) applyContentChange(uri span.URI, content []byte) { // Remove the package and all of its reverse dependencies from the cache. if f.pkg != nil { - v.remove(f.pkg.pkgPath) + v.remove(f.pkg.pkgPath, map[string]struct{}{}) } switch { @@ -191,13 +191,17 @@ func (v *View) applyContentChange(uri span.URI, content []byte) { // remove invalidates a package and its reverse dependencies in the view's // package cache. It is assumed that the caller has locked both the mutexes // of both the mcache and the pcache. -func (v *View) remove(pkgPath string) { +func (v *View) remove(pkgPath string, seen map[string]struct{}) { + if _, ok := seen[pkgPath]; ok { + return + } m, ok := v.mcache.packages[pkgPath] if !ok { return } + seen[pkgPath] = struct{}{} for parentPkgPath := range m.parents { - v.remove(parentPkgPath) + v.remove(parentPkgPath, seen) } // All of the files in the package may also be holding a pointer to the // invalidated package.