Skip to content

Commit

Permalink
Optimize layout cache validating by using RangePointer() and memcmp().
Browse files Browse the repository at this point in the history
  • Loading branch information
zufuliu committed Aug 17, 2020
1 parent de20fab commit 26de7ea
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 9 deletions.
4 changes: 4 additions & 0 deletions scintilla/src/CellBuffer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,10 @@ const char *CellBuffer::RangePointer(Sci::Position position, Sci::Position range
return substance.RangePointer(position, rangeLength);
}

const char *CellBuffer::StyleRangePointer(Sci::Position position, Sci::Position rangeLength) noexcept {
return hasStyles ? style.RangePointer(position, rangeLength) : nullptr;
}

Sci::Position CellBuffer::GapPosition() const noexcept {
return substance.GapPosition();
}
Expand Down
5 changes: 3 additions & 2 deletions scintilla/src/CellBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ class UndoHistory {
*/
class CellBuffer {
private:
bool hasStyles;
bool largeDocument;
const bool hasStyles;
const bool largeDocument;
SplitVector<char> substance;
SplitVector<char> style;
bool readOnly;
Expand Down Expand Up @@ -149,6 +149,7 @@ class CellBuffer {
void GetStyleRange(unsigned char *buffer, Sci::Position position, Sci::Position lengthRetrieve) const;
const char *BufferPointer();
const char *RangePointer(Sci::Position position, Sci::Position rangeLength) noexcept;
const char *StyleRangePointer(Sci::Position position, Sci::Position rangeLength) noexcept;
Sci::Position GapPosition() const noexcept;

Sci::Position Length() const noexcept;
Expand Down
3 changes: 3 additions & 0 deletions scintilla/src/Document.h
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,9 @@ class Document : PerLine, public IDocument, public ILoader {
const char *RangePointer(Sci::Position position, Sci::Position rangeLength) noexcept {
return cb.RangePointer(position, rangeLength);
}
const char *StyleRangePointer(Sci::Position position, Sci::Position rangeLength) noexcept {
return cb.StyleRangePointer(position, rangeLength);
}
Sci::Position GapPosition() const noexcept {
return cb.GapPosition();
}
Expand Down
33 changes: 26 additions & 7 deletions scintilla/src/EditView.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@ void EditView::LayoutLine(const EditModel &model, Sci::Line line, Surface *surfa
// See if chars, styles, indicators, are all the same
int allSame = vstyle.viewEOL ? 0 : (ll->styles[lineLength] ^ model.pdoc->StyleIndexAt(posLineStart + lineLength)); // For eolFilled
// Check base line layout
#if 0
if (vstyle.someStylesForceCase) {
char chPrevious = '\0';
for (Sci::Position numCharsInLine = 0, charInDoc = posLineStart; numCharsInLine < lineLength; ++numCharsInLine, ++charInDoc) {
Expand All @@ -450,13 +451,31 @@ void EditView::LayoutLine(const EditModel &model, Sci::Line line, Surface *surfa
| (ll->chars[numCharsInLine] ^ model.pdoc->CharAt(charInDoc));
}
}
//const double duration = period.Duration()*1e3;
//printf("line=%zd allSame=%d, duration=%f\n", line + 1, allSame, duration);
if (allSame == 0) {
ll->validity = LineLayout::ValidLevel::positions;
} else {
ll->validity = LineLayout::ValidLevel::invalid;
#else
if (lineLength != 0) {
const char *docChars = model.pdoc->RangePointer(posLineStart, lineLength);
const uint8_t *docStyles = reinterpret_cast<const uint8_t *>(model.pdoc->StyleRangePointer(posLineStart, lineLength));
if (docStyles) { // HasStyles
allSame |= ::memcmp(docStyles, ll->styles.get(), lineLength);
}
if (docStyles && vstyle.someStylesForceCase) {
char chPrevious = '\0';
const char *chars = ll->chars.get();
const uint8_t *end = docStyles + lineLength;
do {
const uint8_t styleByte = *docStyles++;
const char chDoc = *docChars++;
allSame |= CaseForce(vstyle.styles[styleByte].caseForce, chDoc, chPrevious) ^ *chars++;
chPrevious = chDoc;
} while (docStyles < end);
} else {
allSame |= ::memcmp(docChars, ll->chars.get(), lineLength);
}
}
#endif
//const double duration = period.Duration()*1e3;
//printf("line=%zd (%zd) allSame=%d, duration=%f\n", line + 1, lineLength, allSame, duration);
ll->validity = allSame ? LineLayout::ValidLevel::invalid : LineLayout::ValidLevel::positions;
} else {
ll->validity = LineLayout::ValidLevel::invalid;
}
Expand All @@ -480,7 +499,7 @@ void EditView::LayoutLine(const EditModel &model, Sci::Line line, Surface *surfa
model.pdoc->GetStyleRange(ll->styles.get(), posLineStart, lineLength);
const int numCharsBeforeEOL = static_cast<int>(model.pdoc->LineEnd(line) - posLineStart);
const int numCharsInLine = vstyle.viewEOL ? lineLength : numCharsBeforeEOL;
const unsigned char styleByteLast = (lineLength > 0) ? (vstyle.viewEOL ? ll->styles[lineLength - 1] : ll->styles[numCharsBeforeEOL]) : 0;
const unsigned char styleByteLast = (lineLength != 0) ? (vstyle.viewEOL ? ll->styles[lineLength - 1] : ll->styles[numCharsBeforeEOL]) : 0;
if (vstyle.someStylesForceCase) {
char chPrevious = '\0';
for (int charInLine = 0; charInLine < lineLength; charInLine++) {
Expand Down

0 comments on commit 26de7ea

Please sign in to comment.