From 2d14f22ef515b936e119940e7738ad1e08fcd2c7 Mon Sep 17 00:00:00 2001 From: Neil Date: Fri, 7 Feb 2025 08:18:53 +1100 Subject: Use operator== inside <= and >= to shorten code. Drop else after return in asymmetric cases to clarify the returned value. --- src/Selection.cxx | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/Selection.cxx b/src/Selection.cxx index 527a9d29a..0de60a958 100644 --- a/src/Selection.cxx +++ b/src/Selection.cxx @@ -81,22 +81,19 @@ void SelectionPosition::MoveForInsertDelete(bool insertion, Sci::Position startC bool SelectionPosition::operator >(const SelectionPosition &other) const noexcept { if (position == other.position) return virtualSpace > other.virtualSpace; - else - return position > other.position; + return position > other.position; } bool SelectionPosition::operator <=(const SelectionPosition &other) const noexcept { - if (position == other.position && virtualSpace == other.virtualSpace) + if (other == *this) return true; - else - return other > *this; + return other > *this; } bool SelectionPosition::operator >=(const SelectionPosition &other) const noexcept { - if (position == other.position && virtualSpace == other.virtualSpace) + if (other == *this) return true; - else - return *this > other; + return *this > other; } std::string SelectionPosition::ToString() const { @@ -215,9 +212,8 @@ bool SelectionRange::Trim(SelectionRange range) noexcept { caret = end; } return Empty(); - } else { - return false; } + return false; } void SelectionRange::Truncate(Sci::Position length) noexcept { @@ -338,9 +334,8 @@ SelectionSegment Selection::Limits() const noexcept { SelectionSegment Selection::LimitsForRectangularElseMain() const noexcept { if (IsRectangular()) { return Limits(); - } else { - return ranges[mainRange].AsSegment(); } + return ranges[mainRange].AsSegment(); } size_t Selection::Count() const noexcept { @@ -375,9 +370,8 @@ const SelectionRange &Selection::RangeMain() const noexcept { SelectionPosition Selection::Start() const noexcept { if (IsRectangular()) { return rangeRectangular.Start(); - } else { - return ranges[mainRange].Start(); } + return ranges[mainRange].Start(); } bool Selection::MoveExtends() const noexcept { -- cgit v1.2.3