diff options
author | mitchell <unknown> | 2019-03-09 16:47:31 -0500 |
---|---|---|
committer | mitchell <unknown> | 2019-03-09 16:47:31 -0500 |
commit | 6a203528af78698780134cf6e71f0b27a4a9c5ba (patch) | |
tree | fb2d98f35460f0da703006de6672b6cdfc0b6e3a | |
parent | 27aec70e5374b672cf7e0c37c4adea7fec031c61 (diff) | |
download | scintilla-mirror-6a203528af78698780134cf6e71f0b27a4a9c5ba.tar.gz |
Backport: Use constexpr where reasonable and move groups of static functions into unnamed namespace.
Backport of changeset 7289:3f930310a0de, but without complicated constexpr
functions, since they are not available in C++11.
-rw-r--r-- | src/Document.cxx | 6 | ||||
-rw-r--r-- | src/Document.h | 2 | ||||
-rw-r--r-- | src/Editor.cxx | 20 |
3 files changed, 18 insertions, 10 deletions
diff --git a/src/Document.cxx b/src/Document.cxx index 86f8b7a38..f1079398d 100644 --- a/src/Document.cxx +++ b/src/Document.cxx @@ -1092,7 +1092,7 @@ int Document::DBCSDrawBytes(const char *text, int len) const noexcept { } } -static inline bool IsSpaceOrTab(int ch) noexcept { +static constexpr bool IsSpaceOrTab(int ch) noexcept { return ch == ' ' || ch == '\t'; } @@ -1438,7 +1438,7 @@ void Document::DelCharBack(Sci::Position pos) { } } -static Sci::Position NextTab(Sci::Position pos, Sci::Position tabSize) noexcept { +static constexpr Sci::Position NextTab(Sci::Position pos, Sci::Position tabSize) noexcept { return ((pos / tabSize) + 1) * tabSize; } @@ -2554,7 +2554,7 @@ Sci::Position Document::WordPartRight(Sci::Position pos) const { return pos; } -static bool IsLineEndChar(char c) noexcept { +static constexpr bool IsLineEndChar(char c) noexcept { return (c == '\n' || c == '\r'); } diff --git a/src/Document.h b/src/Document.h index 2a546847b..f97e1393f 100644 --- a/src/Document.h +++ b/src/Document.h @@ -164,7 +164,7 @@ public: bool isEnabled; }; -inline int LevelNumber(int level) noexcept { +constexpr int LevelNumber(int level) noexcept { return level & SC_FOLDLEVELNUMBERMASK; } diff --git a/src/Editor.cxx b/src/Editor.cxx index 2b4e55bc1..f059a8243 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -58,11 +58,13 @@ using namespace Scintilla; +namespace { + /* return whether this modification represents an operation that may reasonably be deferred (not done now OR [possibly] at all) */ -static bool CanDeferToLastStep(const DocModification &mh) noexcept { +bool CanDeferToLastStep(const DocModification &mh) noexcept { if (mh.modificationType & (SC_MOD_BEFOREINSERT | SC_MOD_BEFOREDELETE)) return true; // CAN skip if (!(mh.modificationType & (SC_PERFORMED_UNDO | SC_PERFORMED_REDO))) @@ -72,7 +74,7 @@ static bool CanDeferToLastStep(const DocModification &mh) noexcept { return false; // PRESUMABLY must do } -static bool CanEliminate(const DocModification &mh) noexcept { +constexpr bool CanEliminate(const DocModification &mh) noexcept { return (mh.modificationType & (SC_MOD_BEFOREINSERT | SC_MOD_BEFOREDELETE)) != 0; } @@ -81,7 +83,7 @@ static bool CanEliminate(const DocModification &mh) noexcept { return whether this modification represents the FINAL step in a [possibly lengthy] multi-step Undo/Redo sequence */ -static bool IsLastStep(const DocModification &mh) noexcept { +constexpr bool IsLastStep(const DocModification &mh) noexcept { return (mh.modificationType & (SC_PERFORMED_UNDO | SC_PERFORMED_REDO)) != 0 && (mh.modificationType & SC_MULTISTEPUNDOREDO) != 0 @@ -89,13 +91,15 @@ static bool IsLastStep(const DocModification &mh) noexcept { && (mh.modificationType & SC_MULTILINEUNDOREDO) != 0; } +} + Timer::Timer() noexcept : ticking(false), ticksToWait(0), tickerID{} {} Idler::Idler() noexcept : state(false), idlerID(0) {} -static inline bool IsAllSpacesOrTabs(const char *s, unsigned int len) noexcept { +static bool IsAllSpacesOrTabs(const char *s, unsigned int len) noexcept { for (unsigned int i = 0; i < len; i++) { // This is safe because IsSpaceOrTab() will return false for null terminators if (!IsSpaceOrTab(s[i])) @@ -2520,8 +2524,10 @@ void Editor::CheckModificationForWrap(DocModification mh) { } } +namespace { + // Move a position so it is still after the same character as before the insertion. -static inline Sci::Position MovePositionForInsertion(Sci::Position position, Sci::Position startInsertion, Sci::Position length) noexcept { +Sci::Position MovePositionForInsertion(Sci::Position position, Sci::Position startInsertion, Sci::Position length) noexcept { if (position > startInsertion) { return position + length; } @@ -2530,7 +2536,7 @@ static inline Sci::Position MovePositionForInsertion(Sci::Position position, Sci // Move a position so it is still after the same character as before the deletion if that // character is still present else after the previous surviving character. -static inline Sci::Position MovePositionForDeletion(Sci::Position position, Sci::Position startDeletion, Sci::Position length) noexcept { +Sci::Position MovePositionForDeletion(Sci::Position position, Sci::Position startDeletion, Sci::Position length) noexcept { if (position > startDeletion) { const Sci::Position endDeletion = startDeletion + length; if (position > endDeletion) { @@ -2543,6 +2549,8 @@ static inline Sci::Position MovePositionForDeletion(Sci::Position position, Sci: } } +} + void Editor::NotifyModified(Document *, DocModification mh, void *) { ContainerNeedsUpdate(SC_UPDATE_CONTENT); if (paintState == painting) { |