sw/source/core/crsr/pam.cxx | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-)
New commits: commit 2053fac9a81927a92aac016eab1b4525c058ce95 Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Fri Jul 22 11:49:07 2022 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Fri Jul 22 22:01:35 2022 +0200 tdf#119840 tweak SwPosition::operator< It is slightly cheaper to check for == first, because that doesn't require fetching data via a pointer to another object. Shaves 7% off load time Change-Id: I4e22e55ed10198a8fadc49de708a5a6b55afc0ac Reviewed-on: https://gerrit.libreoffice.org/c/core/+/137356 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/sw/source/core/crsr/pam.cxx b/sw/source/core/crsr/pam.cxx index f771e09f5739..16c7e6ec21d8 100644 --- a/sw/source/core/crsr/pam.cxx +++ b/sw/source/core/crsr/pam.cxx @@ -79,8 +79,7 @@ SwPosition::SwPosition( SwContentNode & rNode, const sal_Int32 nOffset ) bool SwPosition::operator<(const SwPosition &rPos) const { - if( nNode < rPos.nNode ) - return true; + // cheaper to check for == first if( nNode == rPos.nNode ) { // note that positions with text node but no SwIndex registered are @@ -96,13 +95,12 @@ bool SwPosition::operator<(const SwPosition &rPos) const return pOtherReg != nullptr; } } - return false; + return nNode < rPos.nNode; } bool SwPosition::operator>(const SwPosition &rPos) const { - if(nNode > rPos.nNode ) - return true; + // cheaper to check for == first if( nNode == rPos.nNode ) { // note that positions with text node but no SwIndex registered are @@ -118,13 +116,12 @@ bool SwPosition::operator>(const SwPosition &rPos) const return pThisReg != nullptr; } } - return false; + return nNode > rPos.nNode; } bool SwPosition::operator<=(const SwPosition &rPos) const { - if(nNode < rPos.nNode ) - return true; + // cheaper to check for == first if( nNode == rPos.nNode ) { // note that positions with text node but no SwIndex registered are @@ -140,13 +137,12 @@ bool SwPosition::operator<=(const SwPosition &rPos) const return pThisReg == nullptr; } } - return false; + return nNode < rPos.nNode; } bool SwPosition::operator>=(const SwPosition &rPos) const { - if(nNode > rPos.nNode ) - return true; + // cheaper to check for == first if( nNode == rPos.nNode ) { // note that positions with text node but no SwIndex registered are @@ -162,7 +158,7 @@ bool SwPosition::operator>=(const SwPosition &rPos) const return pOtherReg == nullptr; } } - return false; + return nNode > rPos.nNode; } bool SwPosition::operator==(const SwPosition &rPos) const