From 5ad2dc6896e36aae02d14965f9a98c9778c2e2d1 Mon Sep 17 00:00:00 2001 From: Zufu Liu Date: Sun, 1 Dec 2024 09:04:00 +1100 Subject: Feature [feature-requests:#1535]. Improve performance of DBCS text by avoiding calling LineStartPosition. --- doc/ScintillaHistory.html | 4 ++++ src/Document.cxx | 23 +++++++---------------- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/doc/ScintillaHistory.html b/doc/ScintillaHistory.html index b8fe778a7..84cbab7ad 100644 --- a/doc/ScintillaHistory.html +++ b/doc/ScintillaHistory.html @@ -603,6 +603,10 @@ Feature #1533.
  • + Improve performance of DBCS text. + Feature #1535. +
  • +
  • Fix wrapping removed lines. Bug #2456.
  • diff --git a/src/Document.cxx b/src/Document.cxx index 188ae658f..a601d48ce 100644 --- a/src/Document.cxx +++ b/src/Document.cxx @@ -833,15 +833,9 @@ Sci::Position Document::MovePositionOutsideChar(Sci::Position pos, Sci::Position // Else invalid UTF-8 so return position of isolated trail byte } } else { - // Anchor DBCS calculations at start of line because start of line can - // not be a DBCS trail byte. - const Sci::Position posStartLine = LineStartPosition(pos); - if (pos == posStartLine) - return pos; - // Step back until a non-lead-byte is found. Sci::Position posCheck = pos; - while ((posCheck > posStartLine) && IsDBCSLeadByteNoExcept(cb.CharAt(posCheck-1))) + while ((posCheck > 0) && IsDBCSLeadByteNoExcept(cb.CharAt(posCheck-1))) posCheck--; // Check from known start of character. @@ -916,14 +910,11 @@ Sci::Position Document::NextPosition(Sci::Position pos, int moveDir) const noexc if (pos > cb.Length()) pos = cb.Length(); } else { - // Anchor DBCS calculations at start of line because start of line can - // not be a DBCS trail byte. - const Sci::Position posStartLine = LineStartPosition(pos); - // See http://msdn.microsoft.com/en-us/library/cc194792%28v=MSDN.10%29.aspx - // http://msdn.microsoft.com/en-us/library/cc194790.aspx - if ((pos - 1) <= posStartLine) { - return pos - 1; - } else if (IsDBCSLeadByteNoExcept(cb.CharAt(pos - 1))) { + // How to Go Backward in a DBCS String + // https://msdn.microsoft.com/en-us/library/cc194792.aspx + // DBCS-Enabled Programs vs. Non-DBCS-Enabled Programs + // https://msdn.microsoft.com/en-us/library/cc194790.aspx + if (IsDBCSLeadByteNoExcept(cb.CharAt(pos - 1))) { // Should actually be trail byte if (IsDBCSDualByteAt(pos - 2)) { return pos - 2; @@ -934,7 +925,7 @@ Sci::Position Document::NextPosition(Sci::Position pos, int moveDir) const noexc } else { // Otherwise, step back until a non-lead-byte is found. Sci::Position posTemp = pos - 1; - while (posStartLine <= --posTemp && IsDBCSLeadByteNoExcept(cb.CharAt(posTemp))) + while (--posTemp >= 0 && IsDBCSLeadByteNoExcept(cb.CharAt(posTemp))) ; // Now posTemp+1 must point to the beginning of a character, // so figure out whether we went back an even or an odd -- cgit v1.2.3