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 <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Robert Findley <rfindley@google.com>
This commit is contained in:
Robert Findley 2022-05-28 09:15:37 -04:00
parent ea608150c3
commit 6b760fce76
1 changed files with 7 additions and 15 deletions

View File

@ -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