aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorNeil <nyamatongwe@gmail.com>2020-05-02 09:40:43 +1000
committerNeil <nyamatongwe@gmail.com>2020-05-02 09:40:43 +1000
commitb24183b5a90b4ebeb951668d48f0e95a1a2819dd (patch)
tree457f6a53c34f589b6b9f2956b811e1978d66e135 /src
parent4535b0d9ce9c3be4bb9a02973485427ae67e61d9 (diff)
downloadscintilla-mirror-b24183b5a90b4ebeb951668d48f0e95a1a2819dd.tar.gz
Optimize LineVector by maintaining an activeIndices field to avoid calling
LineStartIndex::Active.
Diffstat (limited to 'src')
-rw-r--r--src/CellBuffer.cxx64
1 files changed, 34 insertions, 30 deletions
diff --git a/src/CellBuffer.cxx b/src/CellBuffer.cxx
index 74fb74816..2715be13f 100644
--- a/src/CellBuffer.cxx
+++ b/src/CellBuffer.cxx
@@ -136,8 +136,15 @@ class LineVector : public ILineVector {
PerLine *perLine;
LineStartIndex<POS> startsUTF16;
LineStartIndex<POS> startsUTF32;
+ int activeIndices;
+
+ void SetActiveIndices() noexcept {
+ activeIndices = (startsUTF32.Active() ? SC_LINECHARACTERINDEX_UTF32 : 0)
+ | (startsUTF16.Active() ? SC_LINECHARACTERINDEX_UTF16 : 0);
+ }
+
public:
- LineVector() : starts(256), perLine(nullptr) {
+ LineVector() : starts(256), perLine(nullptr), activeIndices(0) {
}
// Deleted so LineVector objects can not be copied.
LineVector(const LineVector &) = delete;
@@ -163,13 +170,15 @@ public:
void InsertLine(Sci::Line line, Sci::Position position, bool lineStart) override {
const POS lineAsPos = static_cast<POS>(line);
starts.InsertPartition(lineAsPos, static_cast<POS>(position));
- if (startsUTF32.Active()) {
- startsUTF32.starts.InsertPartition(lineAsPos,
- static_cast<POS>(startsUTF32.starts.PositionFromPartition(lineAsPos - 1) + 1));
- }
- if (startsUTF16.Active()) {
- startsUTF16.starts.InsertPartition(lineAsPos,
- static_cast<POS>(startsUTF16.starts.PositionFromPartition(lineAsPos - 1) + 1));
+ if (activeIndices) {
+ if (activeIndices & SC_LINECHARACTERINDEX_UTF32) {
+ startsUTF32.starts.InsertPartition(lineAsPos,
+ static_cast<POS>(startsUTF32.starts.PositionFromPartition(lineAsPos - 1) + 1));
+ }
+ if (activeIndices & SC_LINECHARACTERINDEX_UTF16) {
+ startsUTF16.starts.InsertPartition(lineAsPos,
+ static_cast<POS>(startsUTF16.starts.PositionFromPartition(lineAsPos - 1) + 1));
+ }
}
if (perLine) {
if ((line > 0) && lineStart)
@@ -182,10 +191,10 @@ public:
}
void RemoveLine(Sci::Line line) override {
starts.RemovePartition(static_cast<POS>(line));
- if (startsUTF32.Active()) {
+ if (activeIndices & SC_LINECHARACTERINDEX_UTF32) {
startsUTF32.starts.RemovePartition(static_cast<POS>(line));
}
- if (startsUTF16.Active()) {
+ if (activeIndices & SC_LINECHARACTERINDEX_UTF16) {
startsUTF16.starts.RemovePartition(static_cast<POS>(line));
}
if (perLine) {
@@ -202,55 +211,50 @@ public:
return starts.PositionFromPartition(static_cast<POS>(line));
}
void InsertCharacters(Sci::Line line, CountWidths delta) noexcept override {
- if (startsUTF32.Active()) {
+ if (activeIndices & SC_LINECHARACTERINDEX_UTF32) {
startsUTF32.starts.InsertText(static_cast<POS>(line), static_cast<POS>(delta.WidthUTF32()));
}
- if (startsUTF16.Active()) {
+ if (activeIndices & SC_LINECHARACTERINDEX_UTF16) {
startsUTF16.starts.InsertText(static_cast<POS>(line), static_cast<POS>(delta.WidthUTF16()));
}
}
void SetLineCharactersWidth(Sci::Line line, CountWidths width) noexcept override {
- if (startsUTF32.Active()) {
+ if (activeIndices & SC_LINECHARACTERINDEX_UTF32) {
assert(startsUTF32.starts.Partitions() == starts.Partitions());
startsUTF32.SetLineWidth(line, width.WidthUTF32());
}
- if (startsUTF16.Active()) {
+ if (activeIndices & SC_LINECHARACTERINDEX_UTF16) {
assert(startsUTF16.starts.Partitions() == starts.Partitions());
startsUTF16.SetLineWidth(line, width.WidthUTF16());
}
}
int LineCharacterIndex() const noexcept override {
- int retVal = 0;
- if (startsUTF32.Active()) {
- retVal |= SC_LINECHARACTERINDEX_UTF32;
- }
- if (startsUTF16.Active()) {
- retVal |= SC_LINECHARACTERINDEX_UTF16;
- }
- return retVal;
+ return activeIndices;
}
bool AllocateLineCharacterIndex(int lineCharacterIndex, Sci::Line lines) override {
- bool changed = false;
+ const int activeIndicesStart = activeIndices;
if ((lineCharacterIndex & SC_LINECHARACTERINDEX_UTF32) != 0) {
- changed = startsUTF32.Allocate(lines) || changed;
+ startsUTF32.Allocate(lines);
assert(startsUTF32.starts.Partitions() == starts.Partitions());
}
if ((lineCharacterIndex & SC_LINECHARACTERINDEX_UTF16) != 0) {
- changed = startsUTF16.Allocate(lines) || changed;
+ startsUTF16.Allocate(lines);
assert(startsUTF16.starts.Partitions() == starts.Partitions());
}
- return changed;
+ SetActiveIndices();
+ return activeIndicesStart != activeIndices;
}
bool ReleaseLineCharacterIndex(int lineCharacterIndex) override {
- bool changed = false;
+ const int activeIndicesStart = activeIndices;
if ((lineCharacterIndex & SC_LINECHARACTERINDEX_UTF32) != 0) {
- changed = startsUTF32.Release() || changed;
+ startsUTF32.Release();
}
if ((lineCharacterIndex & SC_LINECHARACTERINDEX_UTF16) != 0) {
- changed = startsUTF16.Release() || changed;
+ startsUTF16.Release();
}
- return changed;
+ SetActiveIndices();
+ return activeIndicesStart != activeIndices;
}
Sci::Position IndexLineStart(Sci::Line line, int lineCharacterIndex) const noexcept override {
if (lineCharacterIndex == SC_LINECHARACTERINDEX_UTF32) {