From 32ab4a61ccb4ab8d353582ff7d93df4d47716c23 Mon Sep 17 00:00:00 2001 From: Mike Kaganski Date: Tue, 1 Sep 2026 07:08:48 +0000 Subject: [PATCH] Simplify SwPosition comparison operators Drop inequality, that is automatically deduced; and use less-than to define others. Change-Id: Ib979cbe74ec28c1fde0337276d4f602a1fe907b4 Signed-off-by: Mike Kaganski Reviewed-on: https://gerrit.collaboraoffice.com/c/online/+/10674 Tested-by: Jenkins CPCI Reviewed-by: Noel Grandin (cherry picked from commit 9f8156beb5eb02ef7d7b00a3effbd6631fc58dfb) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/210507 Tested-by: Jenkins Reviewed-by: Xisco Fauli --- sw/inc/pam.hxx | 6 ++-- sw/source/core/crsr/pam.cxx | 63 ------------------------------------- 2 files changed, 3 insertions(+), 66 deletions(-) diff --git a/sw/inc/pam.hxx b/sw/inc/pam.hxx index 5b328043e402..afc302ddbffa 100644 --- a/sw/inc/pam.hxx +++ b/sw/inc/pam.hxx @@ -67,9 +67,9 @@ struct SAL_WARN_UNUSED SW_DLLPUBLIC SwPosition SwDoc& GetDoc() const; bool operator < (const SwPosition &) const; - bool operator > (const SwPosition &) const; - bool operator <=(const SwPosition &) const; - bool operator >=(const SwPosition &) const; + bool operator > (const SwPosition & rOther) const { return rOther < *this; } + bool operator <=(const SwPosition & rOther) const { return !(*this > rOther); } + bool operator >=(const SwPosition & rOther) const { return !(*this < rOther); } bool operator ==(const SwPosition &) const; void dumpAsXml(xmlTextWriterPtr pWriter) const; diff --git a/sw/source/core/crsr/pam.cxx b/sw/source/core/crsr/pam.cxx index ba4ff10e672f..1c5eaf1516da 100644 --- a/sw/source/core/crsr/pam.cxx +++ b/sw/source/core/crsr/pam.cxx @@ -140,69 +140,6 @@ bool SwPosition::operator<(const SwPosition &rPos) const return nNode < rPos.nNode; } -bool SwPosition::operator>(const SwPosition &rPos) const -{ - // cheaper to check for == first - if( nNode == rPos.nNode ) - { - // note that positions with text node but no SwContentIndex registered are - // created for text frames anchored at para (see SwXFrame::getAnchor()) - SwContentNode const*const pThisReg(GetContentNode()); - SwContentNode const*const pOtherReg(rPos.GetContentNode()); - if (pThisReg && pOtherReg) - { - return (nContent > rPos.nContent); - } - else // by convention position with no index is smaller - { - return pThisReg != nullptr; - } - } - return nNode > rPos.nNode; -} - -bool SwPosition::operator<=(const SwPosition &rPos) const -{ - // cheaper to check for == first - if( nNode == rPos.nNode ) - { - // note that positions with text node but no SwContentIndex registered are - // created for text frames anchored at para (see SwXFrame::getAnchor()) - SwContentNode const*const pThisReg(GetContentNode()); - SwContentNode const*const pOtherReg(rPos.GetContentNode()); - if (pThisReg && pOtherReg) - { - return (nContent <= rPos.nContent); - } - else // by convention position with no index is smaller - { - return pThisReg == nullptr; - } - } - return nNode < rPos.nNode; -} - -bool SwPosition::operator>=(const SwPosition &rPos) const -{ - // cheaper to check for == first - if( nNode == rPos.nNode ) - { - // note that positions with text node but no SwContentIndex registered are - // created for text frames anchored at para (see SwXFrame::getAnchor()) - SwContentNode const*const pThisReg(GetContentNode()); - SwContentNode const*const pOtherReg(rPos.GetContentNode()); - if (pThisReg && pOtherReg) - { - return (nContent >= rPos.nContent); - } - else // by convention position with no index is smaller - { - return pOtherReg == nullptr; - } - } - return nNode > rPos.nNode; -} - bool SwPosition::operator==(const SwPosition &rPos) const { return (nNode == rPos.nNode)