internal/lsp/cache: don't construct a new metadata graph if no changes

Change-Id: I3f074d1fd29cf7ad0323cec76154f9b2e31f7356
Reviewed-on: https://go-review.googlesource.com/c/tools/+/415494
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
This commit is contained in:
Rob Findley 2022-06-30 14:01:50 -04:00 committed by Robert Findley
parent 8314b7aa0d
commit e8e5b37084
1 changed files with 4 additions and 0 deletions

View File

@ -32,6 +32,10 @@ type metadataGraph struct {
// Clone creates a new metadataGraph, applying the given updates to the
// receiver.
func (g *metadataGraph) Clone(updates map[PackageID]*KnownMetadata) *metadataGraph {
if len(updates) == 0 {
// Optimization: since the graph is immutable, we can return the receiver.
return g
}
result := &metadataGraph{metadata: make(map[PackageID]*KnownMetadata, len(g.metadata))}
// Copy metadata.
for id, m := range g.metadata {