diff options
author | Neil <nyamatongwe@gmail.com> | 2018-10-09 10:39:59 +1100 |
---|---|---|
committer | Neil <nyamatongwe@gmail.com> | 2018-10-09 10:39:59 +1100 |
commit | b2da7da8ece3db03cc3d87b828a8b1b39b880454 (patch) | |
tree | 7a922a6a3fff82b8065f2953236fdef2dfc2e6e2 | |
parent | 5f6858c44289bcafb9c9f0655fe9049619b36548 (diff) | |
download | scintilla-mirror-b2da7da8ece3db03cc3d87b828a8b1b39b880454.tar.gz |
Improve performance of text insertion when Unicode line indexing off.
-rw-r--r-- | doc/ScintillaHistory.html | 3 | ||||
-rw-r--r-- | src/CellBuffer.cxx | 22 | ||||
-rw-r--r-- | src/CellBuffer.h | 1 |
3 files changed, 19 insertions, 7 deletions
diff --git a/doc/ScintillaHistory.html b/doc/ScintillaHistory.html index 5d4e6344d..4b6b8926d 100644 --- a/doc/ScintillaHistory.html +++ b/doc/ScintillaHistory.html @@ -555,6 +555,9 @@ Fixed a crash on Cocoa in bidirectional mode where some patterns of invalid UTF-8 caused failures to create Unicode strings. </li> + <li> + Improve performance of text insertion when Unicode line indexing off. + </li> </ul> <h3> <a href="https://www.scintilla.org/scite412.zip">Release 4.1.2</a> diff --git a/src/CellBuffer.cxx b/src/CellBuffer.cxx index 4c08b0d91..639558a65 100644 --- a/src/CellBuffer.cxx +++ b/src/CellBuffer.cxx @@ -900,6 +900,10 @@ CountWidths CountCharacterWidthsUTF8(std::string_view sv) noexcept { } +bool CellBuffer::MaintainingLineCharacterIndex() const noexcept { + return plv->LineCharacterIndex() != SC_LINECHARACTERINDEX_NONE; +} + void CellBuffer::RecalculateIndexLineStarts(Sci::Line lineFirst, Sci::Line lineLast) { std::string text; Sci::Position posLineEnd = LineStart(lineFirst); @@ -932,8 +936,10 @@ void CellBuffer::BasicInsertString(Sci::Position position, const char *s, Sci::P // A simple insertion is one that inserts valid text on a single line at a character boundary bool simpleInsertion = false; + const bool maintainingIndex = MaintainingLineCharacterIndex(); + // Check for breaking apart a UTF-8 sequence and inserting invalid UTF-8 - if (utf8Substance && (plv->LineCharacterIndex() != SC_LINECHARACTERINDEX_NONE)) { + if (utf8Substance && maintainingIndex) { // Actually, don't need to check that whole insertion is valid just that there // are no potential fragments at ends. simpleInsertion = UTF8IsCharacterBoundary(position) && @@ -1011,11 +1017,13 @@ void CellBuffer::BasicInsertString(Sci::Position position, const char *s, Sci::P chPrev = chAt; } } - if (simpleInsertion) { - const CountWidths cw = CountCharacterWidthsUTF8(std::string_view(s, insertLength)); - plv->InsertCharacters(linePosition, cw); - } else { - RecalculateIndexLineStarts(linePosition, lineInsert - 1); + if (maintainingIndex) { + if (simpleInsertion) { + const CountWidths cw = CountCharacterWidthsUTF8(std::string_view(s, insertLength)); + plv->InsertCharacters(linePosition, cw); + } else { + RecalculateIndexLineStarts(linePosition, lineInsert - 1); + } } } @@ -1043,7 +1051,7 @@ void CellBuffer::BasicDeleteChars(Sci::Position position, Sci::Position deleteLe // Check for breaking apart a UTF-8 sequence // Needs further checks that text is UTF-8 or that some other break apart is occurring - if (utf8Substance && (plv->LineCharacterIndex() != SC_LINECHARACTERINDEX_NONE)) { + if (utf8Substance && MaintainingLineCharacterIndex()) { const Sci::Position posEnd = position + deleteLength; const Sci::Line lineEndRemove = plv->LineFromPosition(posEnd); const bool simpleDeletion = diff --git a/src/CellBuffer.h b/src/CellBuffer.h index b9f2406f1..7d5682260 100644 --- a/src/CellBuffer.h +++ b/src/CellBuffer.h @@ -125,6 +125,7 @@ private: bool UTF8IsCharacterBoundary(Sci::Position position) const; void ResetLineEnds(); void RecalculateIndexLineStarts(Sci::Line lineFirst, Sci::Line lineLast); + bool MaintainingLineCharacterIndex() const noexcept; /// Actions without undo void BasicInsertString(Sci::Position position, const char *s, Sci::Position insertLength); void BasicDeleteChars(Sci::Position position, Sci::Position deleteLength); |