diff options
author | Neil <nyamatongwe@gmail.com> | 2018-10-15 09:13:17 +1100 |
---|---|---|
committer | Neil <nyamatongwe@gmail.com> | 2018-10-15 09:13:17 +1100 |
commit | bf400a65a12475fd60c8a9a213a8bc9956cdeb5f (patch) | |
tree | ce52c4ad60ee3ecf0c7050271543a75a1208ad75 | |
parent | e21a8ca7ecf4001bb3c9a6bcc9d415e60ba2b303 (diff) | |
download | scintilla-mirror-bf400a65a12475fd60c8a9a213a8bc9956cdeb5f.tar.gz |
Set number of lines wrapped in one go to maintain responsiveness and efficiency
by measuring speed and limiting to around 10 milliseconds.
-rw-r--r-- | doc/ScintillaHistory.html | 4 | ||||
-rw-r--r-- | src/Editor.cxx | 14 | ||||
-rw-r--r-- | src/Editor.h | 1 |
3 files changed, 17 insertions, 2 deletions
diff --git a/doc/ScintillaHistory.html b/doc/ScintillaHistory.html index 7e2fc7e2e..19a9f94c5 100644 --- a/doc/ScintillaHistory.html +++ b/doc/ScintillaHistory.html @@ -571,6 +571,10 @@ Released 2 October 2018. </li> <li> + Improve efficiency of idle wrapping by wrapping in blocks as large as possible while + still remaining responsive. + </li> + <li> C++ lexer fixes evaluation of "#elif". <a href="https://sourceforge.net/p/scintilla/bugs/2045/">Bug #2045</a>. </li> diff --git a/src/Editor.cxx b/src/Editor.cxx index c07c0e4a9..082d3d030 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -22,6 +22,7 @@ #include <algorithm> #include <iterator> #include <memory> +#include <chrono> #include "Platform.h" @@ -54,6 +55,7 @@ #include "MarginView.h" #include "EditView.h" #include "Editor.h" +#include "ElapsedPeriod.h" using namespace Scintilla; @@ -103,7 +105,7 @@ static inline bool IsAllSpacesOrTabs(const char *s, unsigned int len) { return true; } -Editor::Editor() { +Editor::Editor() : durationWrapOneLine(0.00001, 0.000001, 0.0001) { ctrlID = 0; stylesValid = false; @@ -1536,7 +1538,12 @@ bool Editor::WrapLines(WrapScope ws) { return false; } } else if (ws == WrapScope::wsIdle) { - lineToWrapEnd = lineToWrap + LinesOnScreen() + 100; + // Try to keep time taken by wrapping reasonable so interaction remains smooth. + const double secondsAllowed = 0.01; + const Sci::Line linesInAllowedTime = std::clamp<Sci::Line>( + static_cast<Sci::Line>(secondsAllowed / durationWrapOneLine.Duration()), + LinesOnScreen() + 50, 0x10000); + lineToWrapEnd = lineToWrap + linesInAllowedTime; } const Sci::Line lineEndNeedWrap = std::min(wrapPending.end, pdoc->LinesTotal()); lineToWrapEnd = std::min(lineToWrapEnd, lineEndNeedWrap); @@ -1555,6 +1562,8 @@ bool Editor::WrapLines(WrapScope ws) { if (surface) { //Platform::DebugPrintf("Wraplines: scope=%0d need=%0d..%0d perform=%0d..%0d\n", ws, wrapPending.start, wrapPending.end, lineToWrap, lineToWrapEnd); + const Sci::Line linesBeingWrapped = lineToWrapEnd - lineToWrap; + ElapsedPeriod epWrapping; while (lineToWrap < lineToWrapEnd) { if (WrapOneLine(surface, lineToWrap)) { wrapOccurred = true; @@ -1562,6 +1571,7 @@ bool Editor::WrapLines(WrapScope ws) { wrapPending.Wrapped(lineToWrap); lineToWrap++; } + durationWrapOneLine.AddSample(linesBeingWrapped, epWrapping.Duration()); goodTopLine = pcs->DisplayFromDoc(lineDocTop) + std::min( subLineTop, static_cast<Sci::Line>(pcs->GetHeight(lineDocTop)-1)); diff --git a/src/Editor.h b/src/Editor.h index a75461afe..a6e059714 100644 --- a/src/Editor.h +++ b/src/Editor.h @@ -250,6 +250,7 @@ protected: // ScintillaBase subclass needs access to much of Editor // Wrapping support WrapPending wrapPending; + ActionDuration durationWrapOneLine; bool convertPastes; |