diff options
author | Neil <nyamatongwe@gmail.com> | 2019-04-28 09:41:51 +1000 |
---|---|---|
committer | Neil <nyamatongwe@gmail.com> | 2019-04-28 09:41:51 +1000 |
commit | 3fbb0e2d513e923f481879c1ce96aacd33f2b8c6 (patch) | |
tree | 8aaf85650ea16ab34a6c563f7f1f6ac3fa7fa05e /src | |
parent | 6a542f10f35a7f6182335250ac6fb25dbd230cac (diff) | |
download | scintilla-mirror-3fbb0e2d513e923f481879c1ce96aacd33f2b8c6.tar.gz |
Remove noexcept from Selection constructor as it allocates memory.
Add noexcept to reader methods and simple writer methods on Selection classes.
Diffstat (limited to 'src')
-rw-r--r-- | src/Selection.cxx | 58 | ||||
-rw-r--r-- | src/Selection.h | 98 |
2 files changed, 78 insertions, 78 deletions
diff --git a/src/Selection.cxx b/src/Selection.cxx index 105b93315..9b08ea001 100644 --- a/src/Selection.cxx +++ b/src/Selection.cxx @@ -23,7 +23,7 @@ using namespace Scintilla; -void SelectionPosition::MoveForInsertDelete(bool insertion, Sci::Position startChange, Sci::Position length) { +void SelectionPosition::MoveForInsertDelete(bool insertion, Sci::Position startChange, Sci::Position length) noexcept { if (insertion) { if (position == startChange) { const Sci::Position virtualLengthRemove = std::min(length, virtualSpace); @@ -48,35 +48,35 @@ void SelectionPosition::MoveForInsertDelete(bool insertion, Sci::Position startC } } -bool SelectionPosition::operator <(const SelectionPosition &other) const { +bool SelectionPosition::operator <(const SelectionPosition &other) const noexcept { if (position == other.position) return virtualSpace < other.virtualSpace; else return position < other.position; } -bool SelectionPosition::operator >(const SelectionPosition &other) const { +bool SelectionPosition::operator >(const SelectionPosition &other) const noexcept { if (position == other.position) return virtualSpace > other.virtualSpace; else return position > other.position; } -bool SelectionPosition::operator <=(const SelectionPosition &other) const { +bool SelectionPosition::operator <=(const SelectionPosition &other) const noexcept { if (position == other.position && virtualSpace == other.virtualSpace) return true; else return other > *this; } -bool SelectionPosition::operator >=(const SelectionPosition &other) const { +bool SelectionPosition::operator >=(const SelectionPosition &other) const noexcept { if (position == other.position && virtualSpace == other.virtualSpace) return true; else return *this > other; } -Sci::Position SelectionRange::Length() const { +Sci::Position SelectionRange::Length() const noexcept { if (anchor > caret) { return anchor.Position() - caret.Position(); } else { @@ -84,33 +84,33 @@ Sci::Position SelectionRange::Length() const { } } -void SelectionRange::MoveForInsertDelete(bool insertion, Sci::Position startChange, Sci::Position length) { +void SelectionRange::MoveForInsertDelete(bool insertion, Sci::Position startChange, Sci::Position length) noexcept { caret.MoveForInsertDelete(insertion, startChange, length); anchor.MoveForInsertDelete(insertion, startChange, length); } -bool SelectionRange::Contains(Sci::Position pos) const { +bool SelectionRange::Contains(Sci::Position pos) const noexcept { if (anchor > caret) return (pos >= caret.Position()) && (pos <= anchor.Position()); else return (pos >= anchor.Position()) && (pos <= caret.Position()); } -bool SelectionRange::Contains(SelectionPosition sp) const { +bool SelectionRange::Contains(SelectionPosition sp) const noexcept { if (anchor > caret) return (sp >= caret) && (sp <= anchor); else return (sp >= anchor) && (sp <= caret); } -bool SelectionRange::ContainsCharacter(Sci::Position posCharacter) const { +bool SelectionRange::ContainsCharacter(Sci::Position posCharacter) const noexcept { if (anchor > caret) return (posCharacter >= caret.Position()) && (posCharacter < anchor.Position()); else return (posCharacter >= anchor.Position()) && (posCharacter < caret.Position()); } -SelectionSegment SelectionRange::Intersect(SelectionSegment check) const { +SelectionSegment SelectionRange::Intersect(SelectionSegment check) const noexcept { const SelectionSegment inOrder(caret, anchor); if ((inOrder.start <= check.end) || (inOrder.end >= check.start)) { SelectionSegment portion = check; @@ -127,11 +127,11 @@ SelectionSegment SelectionRange::Intersect(SelectionSegment check) const { } } -void SelectionRange::Swap() { +void SelectionRange::Swap() noexcept { std::swap(caret, anchor); } -bool SelectionRange::Trim(SelectionRange range) { +bool SelectionRange::Trim(SelectionRange range) noexcept { const SelectionPosition startRange = range.Start(); const SelectionPosition endRange = range.End(); SelectionPosition start = Start(); @@ -167,7 +167,7 @@ bool SelectionRange::Trim(SelectionRange range) { } // If range is all virtual collapse to start of virtual space -void SelectionRange::MinimizeVirtualSpace() { +void SelectionRange::MinimizeVirtualSpace() noexcept { if (caret.Position() == anchor.Position()) { Sci::Position virtualSpace = caret.VirtualSpace(); if (virtualSpace > anchor.VirtualSpace()) @@ -177,14 +177,14 @@ void SelectionRange::MinimizeVirtualSpace() { } } -Selection::Selection() noexcept : mainRange(0), moveExtends(false), tentativeMain(false), selType(selStream) { +Selection::Selection() : mainRange(0), moveExtends(false), tentativeMain(false), selType(selStream) { AddSelection(SelectionRange(SelectionPosition(0))); } Selection::~Selection() { } -bool Selection::IsRectangular() const { +bool Selection::IsRectangular() const noexcept { return (selType == selRectangle) || (selType == selThin); } @@ -196,7 +196,7 @@ Sci::Position Selection::MainAnchor() const { return ranges[mainRange].anchor.Position(); } -SelectionRange &Selection::Rectangular() { +SelectionRange &Selection::Rectangular() noexcept { return rangeRectangular; } @@ -221,15 +221,15 @@ SelectionSegment Selection::LimitsForRectangularElseMain() const { } } -size_t Selection::Count() const { +size_t Selection::Count() const noexcept { return ranges.size(); } -size_t Selection::Main() const { +size_t Selection::Main() const noexcept { return mainRange; } -void Selection::SetMain(size_t r) { +void Selection::SetMain(size_t r) noexcept { PLATFORM_ASSERT(r < ranges.size()); mainRange = r; } @@ -258,15 +258,15 @@ SelectionPosition Selection::Start() const { } } -bool Selection::MoveExtends() const { +bool Selection::MoveExtends() const noexcept { return moveExtends; } -void Selection::SetMoveExtends(bool moveExtends_) { +void Selection::SetMoveExtends(bool moveExtends_) noexcept { moveExtends = moveExtends_; } -bool Selection::Empty() const { +bool Selection::Empty() const noexcept { for (const SelectionRange &range : ranges) { if (!range.Empty()) return false; @@ -274,7 +274,7 @@ bool Selection::Empty() const { return true; } -SelectionPosition Selection::Last() const { +SelectionPosition Selection::Last() const noexcept { SelectionPosition lastPosition; for (const SelectionRange &range : ranges) { if (lastPosition < range.caret) @@ -285,7 +285,7 @@ SelectionPosition Selection::Last() const { return lastPosition; } -Sci::Position Selection::Length() const { +Sci::Position Selection::Length() const noexcept { Sci::Position len = 0; for (const SelectionRange &range : ranges) { len += range.Length(); @@ -293,7 +293,7 @@ Sci::Position Selection::Length() const { return len; } -void Selection::MovePositions(bool insertion, Sci::Position startChange, Sci::Position length) { +void Selection::MovePositions(bool insertion, Sci::Position startChange, Sci::Position length) noexcept { for (SelectionRange &range : ranges) { range.MoveForInsertDelete(insertion, startChange, length); } @@ -372,7 +372,7 @@ void Selection::TentativeSelection(SelectionRange range) { tentativeMain = true; } -void Selection::CommitTentative() { +void Selection::CommitTentative() noexcept { rangesSaved.clear(); tentativeMain = false; } @@ -393,7 +393,7 @@ int Selection::InSelectionForEOL(Sci::Position pos) const { return 0; } -Sci::Position Selection::VirtualSpaceFor(Sci::Position pos) const { +Sci::Position Selection::VirtualSpaceFor(Sci::Position pos) const noexcept { Sci::Position virtualSpace = 0; for (const SelectionRange &range : ranges) { if ((range.caret.Position() == pos) && (virtualSpace < range.caret.VirtualSpace())) @@ -431,7 +431,7 @@ void Selection::RemoveDuplicates() { } } -void Selection::RotateMain() { +void Selection::RotateMain() noexcept { mainRange = (mainRange + 1) % ranges.size(); } diff --git a/src/Selection.h b/src/Selection.h index 82fc4aa48..d078c043e 100644 --- a/src/Selection.h +++ b/src/Selection.h @@ -19,37 +19,37 @@ public: if (virtualSpace < 0) virtualSpace = 0; } - void Reset() { + void Reset() noexcept { position = 0; virtualSpace = 0; } - void MoveForInsertDelete(bool insertion, Sci::Position startChange, Sci::Position length); - bool operator ==(const SelectionPosition &other) const { + void MoveForInsertDelete(bool insertion, Sci::Position startChange, Sci::Position length) noexcept; + bool operator ==(const SelectionPosition &other) const noexcept { return position == other.position && virtualSpace == other.virtualSpace; } - bool operator <(const SelectionPosition &other) const; - bool operator >(const SelectionPosition &other) const; - bool operator <=(const SelectionPosition &other) const; - bool operator >=(const SelectionPosition &other) const; - Sci::Position Position() const { + bool operator <(const SelectionPosition &other) const noexcept; + bool operator >(const SelectionPosition &other) const noexcept; + bool operator <=(const SelectionPosition &other) const noexcept; + bool operator >=(const SelectionPosition &other) const noexcept; + Sci::Position Position() const noexcept { return position; } - void SetPosition(Sci::Position position_) { + void SetPosition(Sci::Position position_) noexcept { position = position_; virtualSpace = 0; } - Sci::Position VirtualSpace() const { + Sci::Position VirtualSpace() const noexcept { return virtualSpace; } - void SetVirtualSpace(Sci::Position virtualSpace_) { + void SetVirtualSpace(Sci::Position virtualSpace_) noexcept { PLATFORM_ASSERT(virtualSpace_ < 800000); if (virtualSpace_ >= 0) virtualSpace = virtualSpace_; } - void Add(Sci::Position increment) { + void Add(Sci::Position increment) noexcept { position = position + increment; } - bool IsValid() const { + bool IsValid() const noexcept { return position >= 0; } }; @@ -58,9 +58,9 @@ public: struct SelectionSegment { SelectionPosition start; SelectionPosition end; - SelectionSegment() : start(), end() { + SelectionSegment() noexcept : start(), end() { } - SelectionSegment(SelectionPosition a, SelectionPosition b) { + SelectionSegment(SelectionPosition a, SelectionPosition b) noexcept { if (a < b) { start = a; end = b; @@ -69,10 +69,10 @@ struct SelectionSegment { end = a; } } - bool Empty() const { + bool Empty() const noexcept { return start == end; } - void Extend(SelectionPosition p) { + void Extend(SelectionPosition p) noexcept { if (start > p) start = p; if (end < p) @@ -94,40 +94,40 @@ struct SelectionRange { } SelectionRange(Sci::Position caret_, Sci::Position anchor_) noexcept : caret(caret_), anchor(anchor_) { } - bool Empty() const { + bool Empty() const noexcept { return anchor == caret; } - Sci::Position Length() const; + Sci::Position Length() const noexcept; // Sci::Position Width() const; // Like Length but takes virtual space into account - bool operator ==(const SelectionRange &other) const { + bool operator ==(const SelectionRange &other) const noexcept { return caret == other.caret && anchor == other.anchor; } - bool operator <(const SelectionRange &other) const { + bool operator <(const SelectionRange &other) const noexcept { return caret < other.caret || ((caret == other.caret) && (anchor < other.anchor)); } - void Reset() { + void Reset() noexcept { anchor.Reset(); caret.Reset(); } - void ClearVirtualSpace() { + void ClearVirtualSpace() noexcept { anchor.SetVirtualSpace(0); caret.SetVirtualSpace(0); } - void MoveForInsertDelete(bool insertion, Sci::Position startChange, Sci::Position length); - bool Contains(Sci::Position pos) const; - bool Contains(SelectionPosition sp) const; - bool ContainsCharacter(Sci::Position posCharacter) const; - SelectionSegment Intersect(SelectionSegment check) const; - SelectionPosition Start() const { + void MoveForInsertDelete(bool insertion, Sci::Position startChange, Sci::Position length) noexcept; + bool Contains(Sci::Position pos) const noexcept; + bool Contains(SelectionPosition sp) const noexcept; + bool ContainsCharacter(Sci::Position posCharacter) const noexcept; + SelectionSegment Intersect(SelectionSegment check) const noexcept; + SelectionPosition Start() const noexcept { return (anchor < caret) ? anchor : caret; } - SelectionPosition End() const { + SelectionPosition End() const noexcept { return (anchor < caret) ? caret : anchor; } - void Swap(); - bool Trim(SelectionRange range); + void Swap() noexcept; + bool Trim(SelectionRange range) noexcept; // If range is all virtual collapse to start of virtual space - void MinimizeVirtualSpace(); + void MinimizeVirtualSpace() noexcept; }; class Selection { @@ -141,31 +141,31 @@ public: enum selTypes { noSel, selStream, selRectangle, selLines, selThin }; selTypes selType; - Selection() noexcept; + Selection(); ~Selection(); - bool IsRectangular() const; + bool IsRectangular() const noexcept; Sci::Position MainCaret() const; Sci::Position MainAnchor() const; - SelectionRange &Rectangular(); + SelectionRange &Rectangular() noexcept; SelectionSegment Limits() const; // This is for when you want to move the caret in response to a // user direction command - for rectangular selections, use the range // that covers all selected text otherwise return the main selection. SelectionSegment LimitsForRectangularElseMain() const; - size_t Count() const; - size_t Main() const; - void SetMain(size_t r); + size_t Count() const noexcept; + size_t Main() const noexcept; + void SetMain(size_t r) noexcept; SelectionRange &Range(size_t r); const SelectionRange &Range(size_t r) const; SelectionRange &RangeMain(); const SelectionRange &RangeMain() const; SelectionPosition Start() const; - bool MoveExtends() const; - void SetMoveExtends(bool moveExtends_); - bool Empty() const; - SelectionPosition Last() const; - Sci::Position Length() const; - void MovePositions(bool insertion, Sci::Position startChange, Sci::Position length); + bool MoveExtends() const noexcept; + void SetMoveExtends(bool moveExtends_) noexcept; + bool Empty() const noexcept; + SelectionPosition Last() const noexcept; + Sci::Position Length() const noexcept; + void MovePositions(bool insertion, Sci::Position startChange, Sci::Position length) noexcept; void TrimSelection(SelectionRange range); void TrimOtherSelections(size_t r, SelectionRange range); void SetSelection(SelectionRange range); @@ -174,14 +174,14 @@ public: void DropSelection(size_t r); void DropAdditionalRanges(); void TentativeSelection(SelectionRange range); - void CommitTentative(); + void CommitTentative() noexcept; int CharacterInSelection(Sci::Position posCharacter) const; int InSelectionForEOL(Sci::Position pos) const; - Sci::Position VirtualSpaceFor(Sci::Position pos) const; + Sci::Position VirtualSpaceFor(Sci::Position pos) const noexcept; void Clear(); void RemoveDuplicates(); - void RotateMain(); - bool Tentative() const { return tentativeMain; } + void RotateMain() noexcept; + bool Tentative() const noexcept { return tentativeMain; } std::vector<SelectionRange> RangesCopy() const { return ranges; } |