aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorZufu Liu <unknown>2022-07-17 14:09:52 +1000
committerZufu Liu <unknown>2022-07-17 14:09:52 +1000
commitf6a9859562ddeb04e882e4a3d15adbf64345452a (patch)
treef814dc8f40ea08c5d01d110ffb69a491806eea36 /src
parent4e0683e5531aa99958fc742476b6150ec2595c72 (diff)
downloadscintilla-mirror-f6a9859562ddeb04e882e4a3d15adbf64345452a.tar.gz
Feature [feature-requests:#1441] Line state optimized to avoid excess allocations
by always allocating for every line.
Diffstat (limited to 'src')
-rw-r--r--src/Document.cxx2
-rw-r--r--src/PerLine.cxx17
-rw-r--r--src/PerLine.h2
3 files changed, 11 insertions, 10 deletions
diff --git a/src/Document.cxx b/src/Document.cxx
index 8e80502e0..5fd2f79e5 100644
--- a/src/Document.cxx
+++ b/src/Document.cxx
@@ -2424,7 +2424,7 @@ void Document::SetLexInterface(std::unique_ptr<LexInterface> pLexInterface) noex
}
int SCI_METHOD Document::SetLineState(Sci_Position line, int state) {
- const int statePrevious = States()->SetLineState(line, state);
+ const int statePrevious = States()->SetLineState(line, state, LinesTotal());
if (state != statePrevious) {
const DocModification mh(ModificationFlags::ChangeLineState, LineStart(line), 0, 0, nullptr,
static_cast<Sci::Line>(line));
diff --git a/src/PerLine.cxx b/src/PerLine.cxx
index 2ea3f0ce4..f3fddcf27 100644
--- a/src/PerLine.cxx
+++ b/src/PerLine.cxx
@@ -262,15 +262,13 @@ void LineLevels::ClearLevels() {
}
int LineLevels::SetLevel(Sci::Line line, int level, Sci::Line lines) {
- int prev = 0;
+ int prev = level;
if ((line >= 0) && (line < lines)) {
if (!levels.Length()) {
ExpandLevels(lines + 1);
}
prev = levels[line];
- if (prev != level) {
- levels[line] = level;
- }
+ levels[line] = level;
}
return prev;
}
@@ -312,10 +310,13 @@ void LineState::RemoveLine(Sci::Line line) {
}
}
-int LineState::SetLineState(Sci::Line line, int state) {
- lineStates.EnsureLength(line + 1);
- const int stateOld = lineStates[line];
- lineStates[line] = state;
+int LineState::SetLineState(Sci::Line line, int state, Sci::Line lines) {
+ int stateOld = state;
+ if ((line >= 0) && (line < lines)) {
+ lineStates.EnsureLength(lines + 1);
+ stateOld = lineStates[line];
+ lineStates[line] = state;
+ }
return stateOld;
}
diff --git a/src/PerLine.h b/src/PerLine.h
index 3f7defa3c..ef9e36932 100644
--- a/src/PerLine.h
+++ b/src/PerLine.h
@@ -111,7 +111,7 @@ public:
void InsertLines(Sci::Line line, Sci::Line lines) override;
void RemoveLine(Sci::Line line) override;
- int SetLineState(Sci::Line line, int state);
+ int SetLineState(Sci::Line line, int state, Sci::Line lines);
int GetLineState(Sci::Line line);
Sci::Line GetMaxLineState() const noexcept;
};