From 6b760fce768b1a06730f6aa3eb17ceeabe4956d1 Mon Sep 17 00:00:00 2001 From: Robert Findley Date: Sat, 28 May 2022 09:15:37 -0400 Subject: [PATCH] internal/lsp/source: remove ineffectual memoization in MappedRange Due to not having a pointer receiver, memoization of the computed MappedRange.protocolRange had no effect. Rather than fix the memoization, just remove it since it has apparently not affected performance significantly. Change-Id: Ib34becef44dca4074dcc7c8af93883d9a1060f8d Reviewed-on: https://go-review.googlesource.com/c/tools/+/408716 Reviewed-by: Alan Donovan gopls-CI: kokoro TryBot-Result: Gopher Robot Run-TryBot: Robert Findley --- internal/lsp/source/util.go | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/internal/lsp/source/util.go b/internal/lsp/source/util.go index ccade4aed2..a9e32e3b5b 100644 --- a/internal/lsp/source/util.go +++ b/internal/lsp/source/util.go @@ -28,10 +28,6 @@ import ( type MappedRange struct { spanRange span.Range // the range in the compiled source (package.CompiledGoFiles) m *protocol.ColumnMapper // a mapper of the edited source (package.GoFiles) - - // protocolRange is the result of converting the spanRange using the mapper. - // It is computed lazily. - protocolRange *protocol.Range } // NewMappedRange returns a MappedRange for the given start and end token.Pos. @@ -63,18 +59,14 @@ func NewMappedRange(fset *token.FileSet, m *protocol.ColumnMapper, start, end to // See the documentation of NewMappedRange for information on edited vs // compiled source. func (s MappedRange) Range() (protocol.Range, error) { - if s.protocolRange == nil { - spn, err := s.Span() - if err != nil { - return protocol.Range{}, err - } - prng, err := s.m.Range(spn) - if err != nil { - return protocol.Range{}, err - } - s.protocolRange = &prng + if s.m == nil { + return protocol.Range{}, bug.Errorf("invalid range") } - return *s.protocolRange, nil + spn, err := s.Span() + if err != nil { + return protocol.Range{}, err + } + return s.m.Range(spn) } // Span returns the span corresponding to the mapped range in the edited