From 946d038c71ae09f3ae403474d66c26c959a18e13 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Sun, 17 Jul 2022 13:45:52 +0200 Subject: [PATCH] tdf#119840 reduce cost of SwPosition::operator<= by fetching Start/End from SwPaM at the same time reduces load time by 5% Change-Id: Ie4a06c667aa0950c04e98e46b30cdc4b97f75ba7 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/137147 Tested-by: Jenkins Reviewed-by: Noel Grandin --- sw/inc/pam.hxx | 6 ++++++ sw/source/core/doc/DocumentRedlineManager.cxx | 13 +++++-------- sw/source/core/doc/docbm.cxx | 3 +-- sw/source/core/unocore/unoportenum.cxx | 4 ++-- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/sw/inc/pam.hxx b/sw/inc/pam.hxx index 7c45c59740d1..4e8d9619dc7f 100644 --- a/sw/inc/pam.hxx +++ b/sw/inc/pam.hxx @@ -220,6 +220,12 @@ public: SwPosition *End() { return (*m_pPoint) > (*m_pMark) ? m_pPoint : m_pMark; } + /// Because sometimes the cost of the operator<= can add up + std::pair StartEnd() const + { if ((*m_pPoint) <= (*m_pMark)) return { m_pPoint, m_pMark }; else return { m_pMark, m_pPoint }; } + std::pair StartEnd() + { if ((*m_pPoint) <= (*m_pMark)) return { m_pPoint, m_pMark }; else return { m_pMark, m_pPoint }; } + /// @return current Node at Point/Mark SwNode & GetNode ( bool bPoint = true ) const { diff --git a/sw/source/core/doc/DocumentRedlineManager.cxx b/sw/source/core/doc/DocumentRedlineManager.cxx index b215170ee36f..9e3d79c14146 100644 --- a/sw/source/core/doc/DocumentRedlineManager.cxx +++ b/sw/source/core/doc/DocumentRedlineManager.cxx @@ -1349,8 +1349,7 @@ DocumentRedlineManager::AppendRedline(SwRangeRedline* pNewRedl, bool const bCall bDec = false; SwRangeRedline* pRedl = maRedlineTable[ n ]; - SwPosition* pRStt = pRedl->Start(), - * pREnd = pRedl->End(); + auto [pRStt, pREnd] = pRedl->StartEnd(); // #i8518# remove empty redlines while we're at it if( ( *pRStt == *pREnd ) && @@ -2460,10 +2459,9 @@ void DocumentRedlineManager::CompressRedlines() { SwRangeRedline* pPrev = maRedlineTable[ n-1 ], * pCur = maRedlineTable[ n ]; - const SwPosition* pPrevStt = pPrev->Start(), - * pPrevEnd = pPrev->End(); - const SwPosition* pCurStt = pCur->Start(), - * pCurEnd = pCur->End(); + auto [pPrevStt,pPrevEnd] = pPrev->StartEnd(); + auto [pCurStt, pCurEnd] = pCur->StartEnd(); + if( *pPrevEnd == *pCurStt && pPrev->CanCombine( *pCur ) && pPrevStt->nNode.GetNode().StartOfSectionNode() == pCurEnd->nNode.GetNode().StartOfSectionNode() && @@ -2771,8 +2769,7 @@ const SwRangeRedline* DocumentRedlineManager::GetRedline( const SwPosition& rPos { nM = nU + ( nO - nU ) / 2; const SwRangeRedline* pRedl = maRedlineTable[ nM ]; - const SwPosition* pStt = pRedl->Start(); - const SwPosition* pEnd = pRedl->End(); + auto [pStt, pEnd] = pRedl->StartEnd(); if( pEnd == pStt ? *pStt == rPos : ( *pStt <= rPos && rPos < *pEnd ) ) diff --git a/sw/source/core/doc/docbm.cxx b/sw/source/core/doc/docbm.cxx index 41d7a6dfb080..a59bb372487f 100644 --- a/sw/source/core/doc/docbm.cxx +++ b/sw/source/core/doc/docbm.cxx @@ -1919,8 +1919,7 @@ void DelBookmarks( for(SwRangeRedline* pRedl : rTable) { // Is at position? - SwPosition *const pRStt = pRedl->Start(); - SwPosition *const pREnd = pRedl->End(); + auto [pRStt, pREnd] = pRedl->StartEnd(); if( lcl_Greater( *pRStt, rStt, pSttIdx ) && lcl_Lower( *pRStt, rEnd, pEndIdx )) { diff --git a/sw/source/core/unocore/unoportenum.cxx b/sw/source/core/unocore/unoportenum.cxx index 30a24721b031..a786340b4e4b 100644 --- a/sw/source/core/unocore/unoportenum.cxx +++ b/sw/source/core/unocore/unoportenum.cxx @@ -1121,12 +1121,12 @@ static void lcl_FillRedlineArray( for(; nRed < nRedTableCount; ++nRed) { const SwRangeRedline* pRedline = rRedTable[nRed]; - const SwPosition* pRedStart = pRedline->Start(); + auto [pRedStart, pRedEnd]= pRedline->StartEnd(); const SwNodeIndex nRedNode = pRedStart->nNode; if ( nOwnNode == nRedNode ) rRedArr.insert( std::make_shared( pRedline, true ) ); - if( pRedline->HasMark() && pRedline->End()->nNode == nOwnNode ) + if( pRedline->HasMark() && pRedEnd->nNode == nOwnNode ) rRedArr.insert( std::make_shared( pRedline, false ) ); }