sw/source/uibase/uiview/viewstat.cxx | 9 ++++----- sw/source/uibase/wrtsh/delete.cxx | 16 ++++++++-------- sw/source/uibase/wrtsh/select.cxx | 16 ++++++++-------- sw/source/uibase/wrtsh/wrtsh1.cxx | 8 ++++---- 4 files changed, 24 insertions(+), 25 deletions(-)
New commits: commit 70015759e2d0ccf3fab0629bbea5c5d44a3975be Author: Noel Grandin <noelgran...@gmail.com> AuthorDate: Sun Aug 7 11:34:47 2022 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Sun Aug 7 21:37:28 2022 +0200 no need to allocate these SwPosition separately It is a small object, and in these places is already contained inside a heap object. Change-Id: Ib9aba6feaf0dd2c24659c03e55fc8a872610cc00 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/137920 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/sw/source/uibase/uiview/viewstat.cxx b/sw/source/uibase/uiview/viewstat.cxx index bcb5f55c2ad7..e002558a6133 100644 --- a/sw/source/uibase/uiview/viewstat.cxx +++ b/sw/source/uibase/uiview/viewstat.cxx @@ -393,23 +393,22 @@ void SwView::GetState(SfxItemSet &rSet) // TODO: adjust this for column selections, where the selected columns // don't contain any redlines and any tracked row changes, but the // adjacent not selected columns do to avoid false Enable - std::unique_ptr<SwPosition> pSelectionEnd; + std::optional<SwPosition> oSelectionEnd; if ( m_pWrtShell->IsTableMode() && m_pWrtShell->GetTableCursor()->GetSelectedBoxesCount() ) { const SwSelBoxes& rBoxes = m_pWrtShell->GetTableCursor()->GetSelectedBoxes(); const SwStartNode *pSttNd = rBoxes.back()->GetSttNd(); const SwNode* pEndNode = pSttNd->GetNodes()[pSttNd->EndOfSectionIndex()]; - pSelectionEnd.reset(new SwPosition(*pEndNode)); + oSelectionEnd.emplace(*pEndNode); } else - pSelectionEnd.reset( - new SwPosition(pCursor->End()->nNode, pCursor->End()->nContent)); + oSelectionEnd.emplace(pCursor->End()->nNode, pCursor->End()->nContent); for(; index < table.size(); ++index ) { const SwRangeRedline* tmp = table[ index ]; - if( *tmp->Start() >= *pSelectionEnd ) + if( *tmp->Start() >= *oSelectionEnd ) break; if( tmp->HasMark() && tmp->IsVisible()) { diff --git a/sw/source/uibase/wrtsh/delete.cxx b/sw/source/uibase/wrtsh/delete.cxx index 5549943ccb7b..dc5ce4b0865e 100644 --- a/sw/source/uibase/wrtsh/delete.cxx +++ b/sw/source/uibase/wrtsh/delete.cxx @@ -426,7 +426,7 @@ bool SwWrtShell::DelRight(bool const isReplaceHeuristic) Point aTmpPt = GetObjRect().TopLeft(); // Remember the anchor of the selected object before deletion. - std::unique_ptr<SwPosition> pAnchor; + std::optional<SwPosition> oAnchor; RndStdIds eAnchorId = RndStdIds::FLY_AT_PARA; SwFlyFrame* pFly = GetSelectedFlyFrame(); SwFrameFormat* pFormat = nullptr; @@ -450,16 +450,16 @@ bool SwWrtShell::DelRight(bool const isReplaceHeuristic) if ((eAnchorId == RndStdIds::FLY_AS_CHAR || eAnchorId == RndStdIds::FLY_AT_CHAR) && pFormat->GetAnchor().GetContentAnchor()) { - pAnchor.reset(new SwPosition(*pFormat->GetAnchor().GetContentAnchor())); + oAnchor.emplace(*pFormat->GetAnchor().GetContentAnchor()); // set cursor before the anchor point if ( IsRedlineOn() ) - *GetCurrentShellCursor().GetPoint() = *pAnchor; + *GetCurrentShellCursor().GetPoint() = *oAnchor; } } } // track changes: create redline at anchor point of the image to record the deletion - if ( IsRedlineOn() && pAnchor && SelectionType::Graphic & nSelection && pFormat && + if ( IsRedlineOn() && oAnchor && SelectionType::Graphic & nSelection && pFormat && ( eAnchorId == RndStdIds::FLY_AT_CHAR || eAnchorId == RndStdIds::FLY_AS_CHAR ) ) { sal_Int32 nRedlineLength = 1; @@ -490,18 +490,18 @@ bool SwWrtShell::DelRight(bool const isReplaceHeuristic) else DelSelectedObj(); - if (pAnchor) + if (oAnchor) { - SwTextNode* pTextNode = pAnchor->GetNode().GetTextNode(); + SwTextNode* pTextNode = oAnchor->GetNode().GetTextNode(); if (pTextNode) { const SwTextField* pField( - pTextNode->GetFieldTextAttrAt(pAnchor->GetContentIndex(), true)); + pTextNode->GetFieldTextAttrAt(oAnchor->GetContentIndex(), true)); if (pField && dynamic_cast<const SwPostItField*>(pField->GetFormatField().GetField())) { // Remove the comment of the deleted object. - *GetCurrentShellCursor().GetPoint() = *pAnchor; + *GetCurrentShellCursor().GetPoint() = *oAnchor; DelRight(); } } diff --git a/sw/source/uibase/wrtsh/select.cxx b/sw/source/uibase/wrtsh/select.cxx index 455835362c88..11e84409941c 100644 --- a/sw/source/uibase/wrtsh/select.cxx +++ b/sw/source/uibase/wrtsh/select.cxx @@ -129,8 +129,8 @@ void SwWrtShell::SelAll() LeaveBlockMode(); SwMvContext aMvContext(this); bool bMoveTable = false; - std::unique_ptr<SwPosition> pStartPos; - std::unique_ptr<SwPosition> pEndPos; + std::optional<SwPosition> oStartPos; + std::optional<SwPosition> oEndPos; SwShellCursor* pTmpCursor = nullptr; // Query these early, before we move the cursor. @@ -144,8 +144,8 @@ void SwWrtShell::SelAll() pTmpCursor = getShellCursor( false ); if( pTmpCursor ) { - pStartPos.reset(new SwPosition( *pTmpCursor->GetPoint() )); - pEndPos.reset(new SwPosition( *pTmpCursor->GetMark() )); + oStartPos.emplace( *pTmpCursor->GetPoint() ); + oEndPos.emplace( *pTmpCursor->GetMark() ); } Push(); bool bIsFullSel = !MoveSection( GoCurrSection, fnSectionStart); @@ -186,7 +186,7 @@ void SwWrtShell::SelAll() pDoc->SetPrepareSelAll(); } - if( pStartPos ) + if( oStartPos ) { pTmpCursor = getShellCursor( false ); if( pTmpCursor ) @@ -196,9 +196,9 @@ void SwWrtShell::SelAll() // if the last selection was behind the first section or // if the last selection was already the first section // In this both cases we select to the end of document - if( ( *pTmpCursor->GetPoint() < *pEndPos || - ( *pStartPos == *pTmpCursor->GetMark() && - *pEndPos == *pTmpCursor->GetPoint() ) ) && !bNeedsExtendedSelectAll) + if( ( *pTmpCursor->GetPoint() < *oEndPos || + ( *oStartPos == *pTmpCursor->GetMark() && + *oEndPos == *pTmpCursor->GetPoint() ) ) && !bNeedsExtendedSelectAll) SwCursorShell::SttEndDoc(false); } } diff --git a/sw/source/uibase/wrtsh/wrtsh1.cxx b/sw/source/uibase/wrtsh/wrtsh1.cxx index 45bac802ccff..94094303adf3 100644 --- a/sw/source/uibase/wrtsh/wrtsh1.cxx +++ b/sw/source/uibase/wrtsh/wrtsh1.cxx @@ -2238,7 +2238,7 @@ void SwWrtShell::InsertPostIt(SwFieldMgr& rFieldMgr, const SfxRequest& rReq) SwFlyFrame* pFly = GetSelectedFlyFrame(); // Remember the anchor of the selected object before deletion. - std::unique_ptr<SwPosition> pAnchor; + std::optional<SwPosition> oAnchor; if (pFly) { SwFrameFormat* pFormat = pFly->GetFormat(); @@ -2247,7 +2247,7 @@ void SwWrtShell::InsertPostIt(SwFieldMgr& rFieldMgr, const SfxRequest& rReq) RndStdIds eAnchorId = pFormat->GetAnchor().GetAnchorId(); if ((eAnchorId == RndStdIds::FLY_AS_CHAR || eAnchorId == RndStdIds::FLY_AT_CHAR) && pFormat->GetAnchor().GetContentAnchor()) { - pAnchor.reset(new SwPosition(*pFormat->GetAnchor().GetContentAnchor())); + oAnchor.emplace(*pFormat->GetAnchor().GetContentAnchor()); } } } @@ -2260,8 +2260,8 @@ void SwWrtShell::InsertPostIt(SwFieldMgr& rFieldMgr, const SfxRequest& rReq) // comment. if (pFly) { - if (pAnchor) - *GetCurrentShellCursor().GetPoint() = *pAnchor; + if (oAnchor) + *GetCurrentShellCursor().GetPoint() = *oAnchor; SwFrameFormat* pFormat = pFly->GetFormat(); if (pFormat && pFormat->GetAnchor().GetAnchorId() == RndStdIds::FLY_AS_CHAR) {