Highlighter engine returns cached spans by reference; drop unneeded mutexes

HighlighterEngine::GetLine copied the span vector on every call (twice
on a miss) and did a dynamic_cast per call; it now returns the cached
entry (valid until the next call) and dispatches on Stateful().

PieceTable and HighlighterEngine took a mutex in their read paths while
their writes took none, and PieceTable.h claimed concurrent reads were
safe; they are not (reads update caches). Every Buffer is used from the
main thread only (the swap writer thread receives copies; the regex
large-stack thread runs while its caller waits), so the mutexes are
removed and the headers say so. ASan and the threaded tests under TSan
are clean.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015rcVQiiWyTzoNrsvLSaAfB
This commit is contained in:
Claude
2026-09-24 12:19:59 -07:00
committed by Kyle Isom
parent 7039c14507
commit d490245f30
8 changed files with 43 additions and 73 deletions
+2 -4
View File
@@ -33,7 +33,8 @@
*
* Implementation notes:
* - Consolidation heuristics prevent piece fragmentation (configurable via SetConsolidationParams)
* - Thread-safe for concurrent reads (mutex protects caches and lazy rebuilds)
* - Not thread-safe: even reads update caches. Buffers are used from the
* main thread only (the swap writer thread gets copies of the bytes).
* - Version tracking invalidates caches on mutations
*/
#pragma once
@@ -43,7 +44,6 @@
#include <ostream>
#include <vector>
#include <limits>
#include <mutex>
#include <string_view>
#include "TextSpan.h"
@@ -297,6 +297,4 @@ private:
mutable RangeCache range_cache_;
mutable FindCache find_cache_;
mutable std::mutex mutex_;
};