aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/PositionCache.cxx
diff options
context:
space:
mode:
authorNeil <nyamatongwe@gmail.com>2021-05-07 23:25:56 +1000
committerNeil <nyamatongwe@gmail.com>2021-05-07 23:25:56 +1000
commit8827755d994e9ebb49097da51a4e460c56385774 (patch)
treed930b836de6b4fe60be2f061cee2d491db58d00c /src/PositionCache.cxx
parent7d47304ca36474000293f267dda39483113c86e3 (diff)
downloadscintilla-mirror-8827755d994e9ebb49097da51a4e460c56385774.tar.gz
Use shared_ptr for LineLayoutCache as it simpifies lifetime management.
AutoLineLayout and other code no longer needed so removed.
Diffstat (limited to 'src/PositionCache.cxx')
-rw-r--r--src/PositionCache.cxx30
1 files changed, 6 insertions, 24 deletions
diff --git a/src/PositionCache.cxx b/src/PositionCache.cxx
index 9ca6db7a3..c1e0a77bd 100644
--- a/src/PositionCache.cxx
+++ b/src/PositionCache.cxx
@@ -60,7 +60,6 @@ void BidiData::Resize(size_t maxLineLength_) {
LineLayout::LineLayout(Sci::Line lineNumber_, int maxLineLength_) :
lenLineStarts(0),
lineNumber(lineNumber_),
- inCache(false),
maxLineLength(-1),
numCharsInLine(0),
numCharsBeforeEOL(0),
@@ -363,7 +362,7 @@ XYPOSITION ScreenLine::TabPositionAfter(XYPOSITION xPosition) const {
LineLayoutCache::LineLayoutCache() :
level(Cache::none),
- allInvalidated(false), styleClock(-1), useCount(0) {
+ allInvalidated(false), styleClock(-1) {
}
LineLayoutCache::~LineLayoutCache() = default;
@@ -394,7 +393,6 @@ size_t LineLayoutCache::EntryForLine(Sci::Line line) const noexcept {
}
void LineLayoutCache::AllocateForLevel(Sci::Line linesOnScreen, Sci::Line linesInDoc) {
- PLATFORM_ASSERT(useCount == 0);
size_t lengthForLevel = 0;
if (level == Cache::caret) {
lengthForLevel = 1;
@@ -405,7 +403,6 @@ void LineLayoutCache::AllocateForLevel(Sci::Line linesOnScreen, Sci::Line linesI
}
if (lengthForLevel != cache.size()) {
- PLATFORM_ASSERT(useCount == 0);
allInvalidated = false;
cache.resize(lengthForLevel);
// Cache::none -> no entries
@@ -449,13 +446,12 @@ void LineLayoutCache::AllocateForLevel(Sci::Line linesOnScreen, Sci::Line linesI
}
void LineLayoutCache::Deallocate() noexcept {
- PLATFORM_ASSERT(useCount == 0);
cache.clear();
}
void LineLayoutCache::Invalidate(LineLayout::ValidLevel validity_) noexcept {
if (!cache.empty() && !allInvalidated) {
- for (const std::unique_ptr<LineLayout> &ll : cache) {
+ for (const std::shared_ptr<LineLayout> &ll : cache) {
if (ll) {
ll->Invalidate(validity_);
}
@@ -475,9 +471,8 @@ void LineLayoutCache::SetLevel(Cache level_) noexcept {
}
}
-LineLayout *LineLayoutCache::Retrieve(Sci::Line lineNumber, Sci::Line lineCaret, int maxChars, int styleClock_,
+std::shared_ptr<LineLayout> LineLayoutCache::Retrieve(Sci::Line lineNumber, Sci::Line lineCaret, int maxChars, int styleClock_,
Sci::Line linesOnScreen, Sci::Line linesInDoc) {
- PLATFORM_ASSERT(useCount == 0);
AllocateForLevel(linesOnScreen, linesInDoc);
if (styleClock != styleClock_) {
Invalidate(LineLayout::ValidLevel::checkTextAndStyle);
@@ -518,9 +513,8 @@ LineLayout *LineLayoutCache::Retrieve(Sci::Line lineNumber, Sci::Line lineCaret,
cache[pos].reset();
}
if (!cache[pos]) {
- cache[pos] = std::make_unique<LineLayout>(lineNumber, maxChars);
+ cache[pos] = std::make_shared<LineLayout>(lineNumber, maxChars);
}
- cache[pos]->inCache = true;
#ifdef CHECK_LLC
// Expensive check that there is only one entry for any line number
std::vector<bool> linesInCache(linesInDoc);
@@ -531,23 +525,11 @@ LineLayout *LineLayoutCache::Retrieve(Sci::Line lineNumber, Sci::Line lineCaret,
}
}
#endif
- useCount++;
- return cache[pos].get();
+ return cache[pos];
}
// Only reach here for level == Cache::none
- return new LineLayout(lineNumber, maxChars);
-}
-
-void LineLayoutCache::Dispose(LineLayout *ll) noexcept {
- allInvalidated = false;
- if (ll) {
- if (!ll->inCache) {
- delete ll;
- } else {
- useCount--;
- }
- }
+ return std::make_shared<LineLayout>(lineNumber, maxChars);
}
// Simply pack the (maximum 4) character bytes into an int