diff options
| author | Paul Buetow <paul@buetow.org> | 2026-03-16 04:03:41 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-03-16 04:03:41 +0200 |
| commit | 030ce454f330871a6be729d7ca8c6ac33e1bbbb5 (patch) | |
| tree | ab6b6666ef632090e983d753c606655839a68697 | |
| parent | 256eccd3f5b40d73c96d69316ecbc170c2159e57 (diff) | |
Use read lock for cache misses in completionState.cacheGet
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
| -rw-r--r-- | internal/lsp/completion_state.go | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/internal/lsp/completion_state.go b/internal/lsp/completion_state.go index 9799561..9f034ab 100644 --- a/internal/lsp/completion_state.go +++ b/internal/lsp/completion_state.go @@ -66,13 +66,18 @@ func (s *completionState) takePendingCompletion(key string) []CompletionItem { return cpy } +// cacheGet returns the cached value for key. A read lock is sufficient for +// cache misses. On a hit we must promote to a write lock so touchLocked can +// update the LRU order. func (s *completionState) cacheGet(key string) (string, bool) { - s.stateMu.Lock() - defer s.stateMu.Unlock() + s.stateMu.RLock() v, ok := s.compCache[key] + s.stateMu.RUnlock() if !ok { return "", false } + s.stateMu.Lock() + defer s.stateMu.Unlock() s.touchLocked(key) return v, true } |
