diff options
| -rw-r--r-- | doc/ScintillaDoc.html | 4 | ||||
| -rw-r--r-- | doc/ScintillaHistory.html | 14 | ||||
| -rw-r--r-- | src/Document.cxx | 2 | ||||
| -rw-r--r-- | src/PerLine.cxx | 17 | ||||
| -rw-r--r-- | src/PerLine.h | 2 | ||||
| -rw-r--r-- | test/unit/testPerLine.cxx | 12 | 
6 files changed, 34 insertions, 17 deletions
diff --git a/doc/ScintillaDoc.html b/doc/ScintillaDoc.html index 1529fc13c..b1d2b5e09 100644 --- a/doc/ScintillaDoc.html +++ b/doc/ScintillaDoc.html @@ -2900,7 +2900,9 @@ struct Sci_TextToFindFull {      </p>      <p><b id="SCI_GETMAXLINESTATE">SCI_GETMAXLINESTATE → int</b><br /> -     This returns the last line that has any line state.</p> +     This returns the last line that has any line state. +     This has been made less useful by an optimization that always allocates for all lines if any line's state was set. +     It can still distinguish cases where line state was never set for any lines.</p>      <h2 id="StyleDefinition">Style definition</h2> diff --git a/doc/ScintillaHistory.html b/doc/ScintillaHistory.html index 8d7952b2d..1ac7da9b0 100644 --- a/doc/ScintillaHistory.html +++ b/doc/ScintillaHistory.html @@ -574,6 +574,20 @@      </table>      <h2>Releases</h2>      <h3> +       <a href="https://www.scintilla.org/scintilla525.zip">Release 5.2.5</a> +    </h3> +    <ul> +	<li> +	Released 10 July 2022. +	</li> +	<li> +	Line state optimized to avoid excess allocations by always allocating for every line. +	This makes SCI_GETMAXLINESTATE less useful although it can still distinguish cases +	where line state was never set for any lines. +	<a href="https://sourceforge.net/p/scintilla/feature-requests/1441/">Feature #1441</a>. +	</li> +    </ul> +    <h3>         <a href="https://www.scintilla.org/scintilla524.zip">Release 5.2.4</a>      </h3>      <ul> 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;  }; diff --git a/test/unit/testPerLine.cxx b/test/unit/testPerLine.cxx index 5209c194e..74881f40e 100644 --- a/test/unit/testPerLine.cxx +++ b/test/unit/testPerLine.cxx @@ -226,11 +226,11 @@ TEST_CASE("LineState") {  	}  	SECTION("SetLineState") { -		REQUIRE(0 == ls.SetLineState(1, 200)); +		REQUIRE(0 == ls.SetLineState(1, 200, 2));  		REQUIRE(0 == ls.GetLineState(0));  		REQUIRE(200 == ls.GetLineState(1));  		REQUIRE(0 == ls.GetLineState(2)); -		REQUIRE(0 == ls.SetLineState(2, 400)); +		REQUIRE(0 == ls.SetLineState(2, 400, 3));  		REQUIRE(0 == ls.GetLineState(0));  		REQUIRE(200 == ls.GetLineState(1));  		REQUIRE(400 == ls.GetLineState(2)); @@ -244,11 +244,11 @@ TEST_CASE("LineState") {  	SECTION("InsertRemoveLine") {  		REQUIRE(0 == ls.GetMaxLineState()); -		ls.SetLineState(1, 1); -		ls.SetLineState(2, 2); -		REQUIRE(3 == ls.GetMaxLineState()); -		ls.InsertLine(2); +		ls.SetLineState(1, 1, 3); +		ls.SetLineState(2, 2, 3);  		REQUIRE(4 == ls.GetMaxLineState()); +		ls.InsertLine(2); +		REQUIRE(5 == ls.GetMaxLineState());  		REQUIRE(0 == ls.GetLineState(0));  		REQUIRE(1 == ls.GetLineState(1));  		REQUIRE(2 == ls.GetLineState(2));  | 
