Skip to content

Commit e8e5b37

Browse files
committed
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 <[email protected]> gopls-CI: kokoro <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Alan Donovan <[email protected]>
1 parent 8314b7a commit e8e5b37

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

internal/lsp/cache/graph.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ type metadataGraph struct {
3232
// Clone creates a new metadataGraph, applying the given updates to the
3333
// receiver.
3434
func (g *metadataGraph) Clone(updates map[PackageID]*KnownMetadata) *metadataGraph {
35+
if len(updates) == 0 {
36+
// Optimization: since the graph is immutable, we can return the receiver.
37+
return g
38+
}
3539
result := &metadataGraph{metadata: make(map[PackageID]*KnownMetadata, len(g.metadata))}
3640
// Copy metadata.
3741
for id, m := range g.metadata {

0 commit comments

Comments
 (0)