Skip to content

Commit

Permalink
Reduce LineLayoutCache::Invalidate() time for replacing text.
Browse files Browse the repository at this point in the history
  • Loading branch information
zufuliu committed Nov 15, 2023
1 parent 6fcc170 commit 077e369
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
19 changes: 9 additions & 10 deletions scintilla/src/PositionCache.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ bool SignificantLines::LineMayCache(Sci::Line line) const noexcept {
LineLayoutCache::LineLayoutCache() noexcept:
lastCaretSlot(SIZE_MAX),
level(LineCache::None),
allInvalidated(false), styleClock(-1) {
maxValidity(LineLayout::ValidLevel::invalid), styleClock(-1) {
}

LineLayoutCache::~LineLayoutCache() = default;
Expand Down Expand Up @@ -703,7 +703,7 @@ void LineLayoutCache::AllocateForLevel(Sci::Line linesOnScreen, Sci::Line linesI
lengthForLevel = NP2_align_up(linesInDoc, 64);
}
if (lengthForLevel != shortCache.size()) {
allInvalidated = false;
maxValidity = LineLayout::ValidLevel::lines;
shortCache.resize(lengthForLevel);
//printf("%s level=%d, size=%zu/%zu, LineLayout=%zu/%zu, BidiData=%zu, XYPOSITION=%zu\n",
// __func__, level, shortCache.size(), shortCache.capacity(), sizeof(LineLayout),
Expand All @@ -713,13 +713,15 @@ void LineLayoutCache::AllocateForLevel(Sci::Line linesOnScreen, Sci::Line linesI
}

void LineLayoutCache::Deallocate() noexcept {
maxValidity = LineLayout::ValidLevel::invalid;
lastCaretSlot = SIZE_MAX;
shortCache.clear();
longCache.clear();
lastCaretSlot = SIZE_MAX;
}

void LineLayoutCache::Invalidate(LineLayout::ValidLevel validity_) noexcept {
if (!allInvalidated) {
if (maxValidity > validity_) {
maxValidity = validity_;
for (const auto &ll : shortCache) {
if (ll) {
ll->Invalidate(validity_);
Expand All @@ -730,19 +732,16 @@ void LineLayoutCache::Invalidate(LineLayout::ValidLevel validity_) noexcept {
ll->Invalidate(validity_);
}
}
if (validity_ == LineLayout::ValidLevel::invalid) {
allInvalidated = true;
}
}
}

void LineLayoutCache::SetLevel(LineCache level_) noexcept {
if (level != level_) {
level = level_;
allInvalidated = false;
maxValidity = LineLayout::ValidLevel::invalid;
lastCaretSlot = SIZE_MAX;
shortCache.clear();
longCache.clear();
lastCaretSlot = SIZE_MAX;
}
}

Expand All @@ -753,7 +752,7 @@ LineLayout *LineLayoutCache::Retrieve(Sci::Line lineNumber, Sci::Line lineCaret,
Invalidate(LineLayout::ValidLevel::checkTextAndStyle);
styleClock = styleClock_;
}
allInvalidated = false;
maxValidity = LineLayout::ValidLevel::lines;

size_t pos = 0;
LineLayout *ret = nullptr;
Expand Down
2 changes: 1 addition & 1 deletion scintilla/src/PositionCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ class LineLayoutCache final {
std::vector<std::unique_ptr<LineLayout>> longCache;
size_t lastCaretSlot;
Scintilla::LineCache level;
bool allInvalidated;
LineLayout::ValidLevel maxValidity;
int styleClock;
void AllocateForLevel(Sci::Line linesOnScreen, Sci::Line linesInDoc);
public:
Expand Down

0 comments on commit 077e369

Please sign in to comment.