aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/PositionCache.cxx
diff options
context:
space:
mode:
authorNeil <nyamatongwe@gmail.com>2021-05-07 17:24:58 +1000
committerNeil <nyamatongwe@gmail.com>2021-05-07 17:24:58 +1000
commitda718f8909b937bd839fc8e09d0b81727644c5fd (patch)
tree58df42332ba07f3c28475461135fef393b99f564 /src/PositionCache.cxx
parented07e1aa1c0c5ae0168add6ed9964c6aefc19578 (diff)
downloadscintilla-mirror-da718f8909b937bd839fc8e09d0b81727644c5fd.tar.gz
Add lineNumber_ argument to LineLayout constructor so always knows which line it
is for. Add accessor for line number and method to say whether compatible with a line number and number of characters. Since LineLayout can report its line number, remove line argument from EditView::LayoutLine which simplifies calling it.
Diffstat (limited to 'src/PositionCache.cxx')
-rw-r--r--src/PositionCache.cxx28
1 files changed, 16 insertions, 12 deletions
diff --git a/src/PositionCache.cxx b/src/PositionCache.cxx
index 87fa544cd..bf7c4623a 100644
--- a/src/PositionCache.cxx
+++ b/src/PositionCache.cxx
@@ -57,9 +57,9 @@ void BidiData::Resize(size_t maxLineLength_) {
widthReprs.resize(maxLineLength_ + 1);
}
-LineLayout::LineLayout(int maxLineLength_) :
+LineLayout::LineLayout(Sci::Line lineNumber_, int maxLineLength_) :
lenLineStarts(0),
- lineNumber(-1),
+ lineNumber(lineNumber_),
inCache(false),
maxLineLength(-1),
numCharsInLine(0),
@@ -117,6 +117,14 @@ void LineLayout::Invalidate(ValidLevel validity_) noexcept {
validity = validity_;
}
+Sci::Line LineLayout::LineNumber() const noexcept {
+ return lineNumber;
+}
+
+bool LineLayout::CanHold(Sci::Line lineDoc, int lineLength_) const noexcept {
+ return (lineNumber == lineDoc) && (lineLength_ <= maxLineLength);
+}
+
int LineLayout::LineStart(int line) const noexcept {
if (line <= 0) {
return 0;
@@ -458,22 +466,20 @@ LineLayout *LineLayoutCache::Retrieve(Sci::Line lineNumber, Sci::Line lineCaret,
}
if (pos < cache.size()) {
- if (cache[pos] &&
- ((cache[pos]->lineNumber != lineNumber) || (cache[pos]->maxLineLength < maxChars))) {
+ if (cache[pos] && !cache[pos]->CanHold(lineNumber, maxChars)) {
cache[pos].reset();
}
if (!cache[pos]) {
- cache[pos] = std::make_unique<LineLayout>(maxChars);
+ cache[pos] = std::make_unique<LineLayout>(lineNumber, maxChars);
}
- cache[pos]->lineNumber = lineNumber;
cache[pos]->inCache = true;
-#ifdef CHECK_LLC_UNIQUE
+#ifndef CHECK_LLC_UNIQUE
// Expensive check that there is only one entry for any line number
std::vector<bool> linesInCache(linesInDoc);
for (const auto &entry : cache) {
if (entry) {
- PLATFORM_ASSERT(!linesInCache[entry->lineNumber]);
- linesInCache[entry->lineNumber] = true;
+ PLATFORM_ASSERT(!linesInCache[entry->LineNumber()]);
+ linesInCache[entry->LineNumber()] = true;
}
}
#endif
@@ -482,9 +488,7 @@ LineLayout *LineLayoutCache::Retrieve(Sci::Line lineNumber, Sci::Line lineCaret,
}
// Only reach here for level == Cache::none
- LineLayout *ret = new LineLayout(maxChars);
- ret->lineNumber = lineNumber;
- return ret;
+ return new LineLayout(lineNumber, maxChars);
}
void LineLayoutCache::Dispose(LineLayout *ll) noexcept {