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 <iancottrell@google.com> Run-TryBot: Rebecca Stambler <rstambler@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
36ba6a502a
commit
4c644d7e32
|
@ -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.
|
// Remove the package and all of its reverse dependencies from the cache.
|
||||||
if f.pkg != nil {
|
if f.pkg != nil {
|
||||||
v.remove(f.pkg.pkgPath)
|
v.remove(f.pkg.pkgPath, map[string]struct{}{})
|
||||||
}
|
}
|
||||||
|
|
||||||
switch {
|
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
|
// 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
|
// package cache. It is assumed that the caller has locked both the mutexes
|
||||||
// of both the mcache and the pcache.
|
// 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]
|
m, ok := v.mcache.packages[pkgPath]
|
||||||
if !ok {
|
if !ok {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
seen[pkgPath] = struct{}{}
|
||||||
for parentPkgPath := range m.parents {
|
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
|
// All of the files in the package may also be holding a pointer to the
|
||||||
// invalidated package.
|
// invalidated package.
|
||||||
|
|
Loading…
Reference in New Issue