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 <noel.grandin@collabora.co.uk>
This commit is contained in:
Noel Grandin
2022-07-17 13:45:52 +02:00
parent 868b45039d
commit 946d038c71
4 changed files with 14 additions and 12 deletions

View File

@@ -220,6 +220,12 @@ public:
SwPosition *End() SwPosition *End()
{ return (*m_pPoint) > (*m_pMark) ? m_pPoint : m_pMark; } { return (*m_pPoint) > (*m_pMark) ? m_pPoint : m_pMark; }
/// Because sometimes the cost of the operator<= can add up
std::pair<const SwPosition *, const SwPosition *> StartEnd() const
{ if ((*m_pPoint) <= (*m_pMark)) return { m_pPoint, m_pMark }; else return { m_pMark, m_pPoint }; }
std::pair<SwPosition *, SwPosition *> StartEnd()
{ if ((*m_pPoint) <= (*m_pMark)) return { m_pPoint, m_pMark }; else return { m_pMark, m_pPoint }; }
/// @return current Node at Point/Mark /// @return current Node at Point/Mark
SwNode & GetNode ( bool bPoint = true ) const SwNode & GetNode ( bool bPoint = true ) const
{ {

View File

@@ -1349,8 +1349,7 @@ DocumentRedlineManager::AppendRedline(SwRangeRedline* pNewRedl, bool const bCall
bDec = false; bDec = false;
SwRangeRedline* pRedl = maRedlineTable[ n ]; SwRangeRedline* pRedl = maRedlineTable[ n ];
SwPosition* pRStt = pRedl->Start(), auto [pRStt, pREnd] = pRedl->StartEnd();
* pREnd = pRedl->End();
// #i8518# remove empty redlines while we're at it // #i8518# remove empty redlines while we're at it
if( ( *pRStt == *pREnd ) && if( ( *pRStt == *pREnd ) &&
@@ -2460,10 +2459,9 @@ void DocumentRedlineManager::CompressRedlines()
{ {
SwRangeRedline* pPrev = maRedlineTable[ n-1 ], SwRangeRedline* pPrev = maRedlineTable[ n-1 ],
* pCur = maRedlineTable[ n ]; * pCur = maRedlineTable[ n ];
const SwPosition* pPrevStt = pPrev->Start(), auto [pPrevStt,pPrevEnd] = pPrev->StartEnd();
* pPrevEnd = pPrev->End(); auto [pCurStt, pCurEnd] = pCur->StartEnd();
const SwPosition* pCurStt = pCur->Start(),
* pCurEnd = pCur->End();
if( *pPrevEnd == *pCurStt && pPrev->CanCombine( *pCur ) && if( *pPrevEnd == *pCurStt && pPrev->CanCombine( *pCur ) &&
pPrevStt->nNode.GetNode().StartOfSectionNode() == pPrevStt->nNode.GetNode().StartOfSectionNode() ==
pCurEnd->nNode.GetNode().StartOfSectionNode() && pCurEnd->nNode.GetNode().StartOfSectionNode() &&
@@ -2771,8 +2769,7 @@ const SwRangeRedline* DocumentRedlineManager::GetRedline( const SwPosition& rPos
{ {
nM = nU + ( nO - nU ) / 2; nM = nU + ( nO - nU ) / 2;
const SwRangeRedline* pRedl = maRedlineTable[ nM ]; const SwRangeRedline* pRedl = maRedlineTable[ nM ];
const SwPosition* pStt = pRedl->Start(); auto [pStt, pEnd] = pRedl->StartEnd();
const SwPosition* pEnd = pRedl->End();
if( pEnd == pStt if( pEnd == pStt
? *pStt == rPos ? *pStt == rPos
: ( *pStt <= rPos && rPos < *pEnd ) ) : ( *pStt <= rPos && rPos < *pEnd ) )

View File

@@ -1919,8 +1919,7 @@ void DelBookmarks(
for(SwRangeRedline* pRedl : rTable) for(SwRangeRedline* pRedl : rTable)
{ {
// Is at position? // Is at position?
SwPosition *const pRStt = pRedl->Start(); auto [pRStt, pREnd] = pRedl->StartEnd();
SwPosition *const pREnd = pRedl->End();
if( lcl_Greater( *pRStt, rStt, pSttIdx ) && lcl_Lower( *pRStt, rEnd, pEndIdx )) if( lcl_Greater( *pRStt, rStt, pSttIdx ) && lcl_Lower( *pRStt, rEnd, pEndIdx ))
{ {

View File

@@ -1121,12 +1121,12 @@ static void lcl_FillRedlineArray(
for(; nRed < nRedTableCount; ++nRed) for(; nRed < nRedTableCount; ++nRed)
{ {
const SwRangeRedline* pRedline = rRedTable[nRed]; const SwRangeRedline* pRedline = rRedTable[nRed];
const SwPosition* pRedStart = pRedline->Start(); auto [pRedStart, pRedEnd]= pRedline->StartEnd();
const SwNodeIndex nRedNode = pRedStart->nNode; const SwNodeIndex nRedNode = pRedStart->nNode;
if ( nOwnNode == nRedNode ) if ( nOwnNode == nRedNode )
rRedArr.insert( std::make_shared<SwXRedlinePortion_Impl>( rRedArr.insert( std::make_shared<SwXRedlinePortion_Impl>(
pRedline, true ) ); pRedline, true ) );
if( pRedline->HasMark() && pRedline->End()->nNode == nOwnNode ) if( pRedline->HasMark() && pRedEnd->nNode == nOwnNode )
rRedArr.insert( std::make_shared<SwXRedlinePortion_Impl>( rRedArr.insert( std::make_shared<SwXRedlinePortion_Impl>(
pRedline, false ) ); pRedline, false ) );
} }