Skip to content

Commit 4c644d7

Browse files
committed
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 <[email protected]> Run-TryBot: Rebecca Stambler <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent 36ba6a5 commit 4c644d7

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

internal/lsp/cache/view.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ func (v *View) applyContentChange(uri span.URI, content []byte) {
172172

173173
// Remove the package and all of its reverse dependencies from the cache.
174174
if f.pkg != nil {
175-
v.remove(f.pkg.pkgPath)
175+
v.remove(f.pkg.pkgPath, map[string]struct{}{})
176176
}
177177

178178
switch {
@@ -191,13 +191,17 @@ func (v *View) applyContentChange(uri span.URI, content []byte) {
191191
// remove invalidates a package and its reverse dependencies in the view's
192192
// package cache. It is assumed that the caller has locked both the mutexes
193193
// of both the mcache and the pcache.
194-
func (v *View) remove(pkgPath string) {
194+
func (v *View) remove(pkgPath string, seen map[string]struct{}) {
195+
if _, ok := seen[pkgPath]; ok {
196+
return
197+
}
195198
m, ok := v.mcache.packages[pkgPath]
196199
if !ok {
197200
return
198201
}
202+
seen[pkgPath] = struct{}{}
199203
for parentPkgPath := range m.parents {
200-
v.remove(parentPkgPath)
204+
v.remove(parentPkgPath, seen)
201205
}
202206
// All of the files in the package may also be holding a pointer to the
203207
// invalidated package.

0 commit comments

Comments
 (0)