Skip to content

Commit

Permalink
internal/lsp/cache: don't construct a new metadata graph if no changes
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
findleyr committed Jun 30, 2022
1 parent 8314b7a commit e8e5b37
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions internal/lsp/cache/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit e8e5b37

Please sign in to comment.