sw/inc/pam.hxx                                            |   12 ++++++---
 sw/qa/extras/globalfilter/globalfilter.cxx                |    2 -
 sw/qa/extras/uiwriter/uiwriter2.cxx                       |    2 -
 sw/source/core/crsr/pam.cxx                               |   17 +++++++++-----
 sw/source/core/doc/DocumentContentOperationsManager.cxx   |    3 --
 sw/source/core/doc/DocumentLinksAdministrationManager.cxx |    2 -
 sw/source/core/docnode/ndtbl.cxx                          |    2 -
 sw/source/core/fields/docufld.cxx                         |    2 -
 sw/source/core/fields/expfld.cxx                          |    2 -
 sw/source/core/layout/fly.cxx                             |    2 -
 sw/source/core/table/swtable.cxx                          |    4 +--
 sw/source/core/undo/unsect.cxx                            |    4 +--
 sw/source/core/undo/untbl.cxx                             |    9 +++----
 sw/source/core/unocore/unotext.cxx                        |    5 +---
 sw/source/filter/ww8/writerhelper.cxx                     |    5 +---
 15 files changed, 39 insertions(+), 34 deletions(-)

New commits:
commit 9acc54e65476e405bd8d9e4bca135be968448d3c
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Mon Jul 25 13:32:18 2022 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Tue Jul 26 07:54:25 2022 +0200

    elide some temporaries when constructing SwPosition
    
    because the resulting pointer manipulation is not free, the temporary
    has to be attached to a linked list and then immediately de-linked
    
    Change-Id: I10594026aa388064abc652b91aff024deeb5ca54
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/137410
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/sw/inc/pam.hxx b/sw/inc/pam.hxx
index fad762cab0e8..68282d98ca4e 100644
--- a/sw/inc/pam.hxx
+++ b/sw/inc/pam.hxx
@@ -39,9 +39,13 @@ struct SAL_WARN_UNUSED SW_DLLPUBLIC SwPosition
     SwContentIndex nContent;
 
     SwPosition( const SwNodeIndex &rNode, const SwContentIndex &rContent );
-    explicit SwPosition( const SwNodeIndex &rNode );
-    explicit SwPosition( const SwNode& rNode );
-    explicit SwPosition( const SwContentNode& rNode, const sal_Int32 nOffset = 
0 );
+    explicit SwPosition( SwNodes& rNodes, SwNodeOffset nIndex = 
SwNodeOffset(0) );
+    explicit SwPosition( const SwNodeIndex &rNode, SwNodeOffset nDiff = 
SwNodeOffset(0) );
+    explicit SwPosition( const SwNode& rNode, SwNodeOffset nDiff = 
SwNodeOffset(0) );
+    explicit SwPosition( const SwContentNode& rNode, const sal_Int32 
nContentOffset = 0 );
+
+    // callers should be using one of the other constructors to avoid creating 
a temporary
+    SwPosition( SwNodeIndex && ) = delete;
 
     /**
        Returns the document this position is in.
@@ -181,7 +185,7 @@ public:
         {
             /** clear the mark position; this helps if mark's SwContentIndex is
                registered at some node, and that node is then deleted */
-            *m_pMark = SwPosition( SwNodeIndex( GetNode().GetNodes() ) );
+            *m_pMark = SwPosition( GetNode().GetNodes() );
             m_pMark = m_pPoint;
         }
     }
diff --git a/sw/qa/extras/globalfilter/globalfilter.cxx 
b/sw/qa/extras/globalfilter/globalfilter.cxx
index fefc1fbda8ee..654eb662786a 100644
--- a/sw/qa/extras/globalfilter/globalfilter.cxx
+++ b/sw/qa/extras/globalfilter/globalfilter.cxx
@@ -1242,7 +1242,7 @@ void Test::testRedlineFlags()
     CPPUNIT_ASSERT(pTextDoc);
     SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
 
-    SwPaM pam(SwPosition(SwNodeIndex(pDoc->GetNodes().GetEndOfContent(), -1)));
+    SwPaM pam(SwPosition(pDoc->GetNodes().GetEndOfContent(), 
SwNodeOffset(-1)));
     pDoc->getIDocumentContentOperations().InsertString(pam, "foo bar baz");
 
     IDocumentRedlineAccess & rIDRA(pDoc->getIDocumentRedlineAccess());
diff --git a/sw/qa/extras/uiwriter/uiwriter2.cxx 
b/sw/qa/extras/uiwriter/uiwriter2.cxx
index 38247a36ea4d..aa5515b131a1 100644
--- a/sw/qa/extras/uiwriter/uiwriter2.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter2.cxx
@@ -807,7 +807,7 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf131912)
     sw::UndoManager& rUndoManager = pDoc->GetUndoManager();
 
     sw::UnoCursorPointer pCursor(
-        
pDoc->CreateUnoCursor(SwPosition(SwNodeIndex(pDoc->GetNodes().GetEndOfContent(),
 -1))));
+        pDoc->CreateUnoCursor(SwPosition(pDoc->GetNodes().GetEndOfContent(), 
SwNodeOffset(-1))));
 
     pDoc->getIDocumentContentOperations().InsertString(*pCursor, "foo");
 
diff --git a/sw/source/core/crsr/pam.cxx b/sw/source/core/crsr/pam.cxx
index 0ba3705781bd..4bd4ee78f839 100644
--- a/sw/source/core/crsr/pam.cxx
+++ b/sw/source/core/crsr/pam.cxx
@@ -62,18 +62,23 @@ SwPosition::SwPosition( const SwNodeIndex & rNodeIndex, 
const SwContentIndex & r
 {
 }
 
-SwPosition::SwPosition( const SwNodeIndex & rNodeIndex )
-    : nNode( rNodeIndex ), nContent( nNode.GetNode().GetContentNode() )
+SwPosition::SwPosition( const SwNodeIndex & rNodeIndex, SwNodeOffset nDiff )
+    : nNode( rNodeIndex, nDiff ), nContent( nNode.GetNode().GetContentNode() )
 {
 }
 
-SwPosition::SwPosition( const SwNode& rNode )
-    : nNode( rNode ), nContent( nNode.GetNode().GetContentNode() )
+SwPosition::SwPosition( const SwNode& rNode, SwNodeOffset nDiff )
+    : nNode( rNode, nDiff ), nContent( nNode.GetNode().GetContentNode() )
 {
 }
 
-SwPosition::SwPosition( const SwContentNode & rNode, const sal_Int32 nOffset )
-    : nNode( rNode ), nContent( const_cast<SwContentNode*>(&rNode), nOffset )
+SwPosition::SwPosition( SwNodes& rNodes, SwNodeOffset nIndex )
+    : nNode( rNodes, nIndex ), nContent( nNode.GetNode().GetContentNode() )
+{
+}
+
+SwPosition::SwPosition( const SwContentNode & rNode, const sal_Int32 
nContentOffset )
+    : nNode( rNode ), nContent( const_cast<SwContentNode*>(&rNode), 
nContentOffset )
 {
 }
 
diff --git a/sw/source/core/doc/DocumentContentOperationsManager.cxx 
b/sw/source/core/doc/DocumentContentOperationsManager.cxx
index 6820a0c4621c..41ef175cd301 100644
--- a/sw/source/core/doc/DocumentContentOperationsManager.cxx
+++ b/sw/source/core/doc/DocumentContentOperationsManager.cxx
@@ -3677,8 +3677,7 @@ void DocumentContentOperationsManager::CopyWithFlyInFly(
     if (m_rDoc.getIDocumentMarkAccess()->getAllMarksCount())
     {
         SwPaM aRgTmp( rRg.aStart, rRg.aEnd );
-        SwPosition targetPos(SwNodeIndex(aSavePos,
-                                         SwNodeOffset(rRg.aStart != rRg.aEnd ? 
+1 : 0)));
+        SwPosition targetPos(aSavePos, SwNodeOffset(rRg.aStart != rRg.aEnd ? 
+1 : 0));
         if (pCopiedPaM && rRg.aStart != pCopiedPaM->first.Start()->nNode)
         {
             // there is 1 (partially selected, maybe) paragraph before
diff --git a/sw/source/core/doc/DocumentLinksAdministrationManager.cxx 
b/sw/source/core/doc/DocumentLinksAdministrationManager.cxx
index 175b50caba8e..2d7d6059dd7b 100644
--- a/sw/source/core/doc/DocumentLinksAdministrationManager.cxx
+++ b/sw/source/core/doc/DocumentLinksAdministrationManager.cxx
@@ -505,7 +505,7 @@ bool DocumentLinksAdministrationManager::SelectServerObj( 
std::u16string_view rS
         }
         else if( sCmp == u"outline" )
         {
-            SwPosition aPos( SwNodeIndex( m_rDoc.GetNodes() ));
+            SwPosition aPos( m_rDoc.GetNodes() );
             if (m_rDoc.GotoOutline(aPos, sName, nullptr))
             {
                 SwNode* pNd = &aPos.nNode.GetNode();
diff --git a/sw/source/core/docnode/ndtbl.cxx b/sw/source/core/docnode/ndtbl.cxx
index 935896331d74..ebb7f41daf09 100644
--- a/sw/source/core/docnode/ndtbl.cxx
+++ b/sw/source/core/docnode/ndtbl.cxx
@@ -4360,7 +4360,7 @@ bool SwDoc::InsCopyOfTable( SwPosition& rInsPos, const 
SwSelBoxes& rBoxes,
             // Copy the Table into a temporary Doc
             xCpyDoc = new SwDoc;
 
-            SwPosition aPos( SwNodeIndex( 
xCpyDoc->GetNodes().GetEndOfContent() ));
+            SwPosition aPos( xCpyDoc->GetNodes().GetEndOfContent() );
             if( !pSrcTableNd->GetTable().MakeCopy( *xCpyDoc, aPos, rBoxes, 
true ))
             {
                 xCpyDoc.clear();
diff --git a/sw/source/core/fields/docufld.cxx 
b/sw/source/core/fields/docufld.cxx
index 289061a283e5..a773904615b0 100644
--- a/sw/source/core/fields/docufld.cxx
+++ b/sw/source/core/fields/docufld.cxx
@@ -2382,7 +2382,7 @@ void SwRefPageGetField::ChangeExpansion(const SwFrame& 
rFrame,
         return ;
 
     //  create index for determination of the TextNode
-    SwPosition aPos( SwNodeIndex( rDoc.GetNodes() ) );
+    SwPosition aPos( rDoc.GetNodes() );
     SwTextNode* pTextNode = const_cast<SwTextNode*>(GetBodyTextNode(rDoc, 
aPos, rFrame));
 
     // If no layout exists, ChangeExpansion is called for header and
diff --git a/sw/source/core/fields/expfld.cxx b/sw/source/core/fields/expfld.cxx
index 978b8ee30fd8..0a977e544a3b 100644
--- a/sw/source/core/fields/expfld.cxx
+++ b/sw/source/core/fields/expfld.cxx
@@ -353,7 +353,7 @@ void SwGetExpField::ChangeExpansion( const SwFrame& rFrame, 
const SwTextField& r
     SwDoc& rDoc = const_cast<SwDoc&>(pTextNode->GetDoc());
 
     // create index for determination of the TextNode
-    SwPosition aPos( SwNodeIndex( rDoc.GetNodes() ) );
+    SwPosition aPos( rDoc.GetNodes() );
     pTextNode = GetBodyTextNode( rDoc, aPos, rFrame );
 
     // If no layout exists, ChangeExpansion is called for header and
diff --git a/sw/source/core/layout/fly.cxx b/sw/source/core/layout/fly.cxx
index 5b4ba3238a6f..9343dba90d69 100644
--- a/sw/source/core/layout/fly.cxx
+++ b/sw/source/core/layout/fly.cxx
@@ -376,7 +376,7 @@ static SwPosition ResolveFlyAnchor(SwFrameFormat const& 
rFlyFrame)
     SwFormatAnchor const& rAnch(rFlyFrame.GetAnchor());
     if (rAnch.GetAnchorId() == RndStdIds::FLY_AT_PAGE)
     {   // arbitrarily pick last node
-        return 
SwPosition(SwNodeIndex(rFlyFrame.GetDoc()->GetNodes().GetEndOfContent(), -1));
+        return SwPosition(rFlyFrame.GetDoc()->GetNodes().GetEndOfContent(), 
SwNodeOffset(-1));
     }
     else
     {
diff --git a/sw/source/core/table/swtable.cxx b/sw/source/core/table/swtable.cxx
index e3efd0416d6c..84ae10f3728e 100644
--- a/sw/source/core/table/swtable.cxx
+++ b/sw/source/core/table/swtable.cxx
@@ -1635,8 +1635,8 @@ SwRedlineTable::size_type 
SwTableLine::UpdateTextChangesOnly(
             }
 
             bool bHasRedlineInBox = false;
-            SwPosition aCellStart( SwNodeIndex( *pBox->GetSttNd(), 0 ) );
-            SwPosition aCellEnd( SwNodeIndex( 
*pBox->GetSttNd()->EndOfSectionNode(), -1 ) );
+            SwPosition aCellStart( *pBox->GetSttNd(), SwNodeOffset(0) );
+            SwPosition aCellEnd( *pBox->GetSttNd()->EndOfSectionNode(), 
SwNodeOffset(-1) );
             SwNodeIndex pEndNodeIndex(aCellEnd.nNode.GetNode());
             SwRangeRedline* pPreviousDeleteRedline = nullptr;
             for( ; rRedlinePos < aRedlineTable.size(); ++rRedlinePos )
diff --git a/sw/source/core/undo/unsect.cxx b/sw/source/core/undo/unsect.cxx
index 64fa2d7a2176..168a18a50c03 100644
--- a/sw/source/core/undo/unsect.cxx
+++ b/sw/source/core/undo/unsect.cxx
@@ -579,7 +579,7 @@ void SwUndoUpdateIndex::UndoImpl(::sw::UndoRedoContext & 
rContext)
     m_pSaveSectionOriginal->RestoreSection(&rDoc, first, true);
     // delete before restoring nested undo, so its node indexes match
     SwNodeIndex const del(*pDeletionPrevention);
-    SwDoc::CorrAbs(del, del, 
SwPosition(SwNodeIndex(*rDoc.GetNodes()[m_nStartIndex]->EndOfSectionNode())), 
true);
+    SwDoc::CorrAbs(del, del, 
SwPosition(*rDoc.GetNodes()[m_nStartIndex]->EndOfSectionNode(), 
SwNodeOffset(0)), true);
     rDoc.GetNodes().Delete(del);
     // original title section will be restored by next Undo, see ctor!
 }
@@ -600,7 +600,7 @@ void SwUndoUpdateIndex::RedoImpl(::sw::UndoRedoContext & 
rContext)
     m_pSaveSectionUpdated->RestoreSection(&rDoc, first, true);
     // delete before restoring nested undo, so its node indexes match
     SwNodeIndex const del(*pDeletionPrevention);
-    SwDoc::CorrAbs(del, del, 
SwPosition(SwNodeIndex(*rDoc.GetNodes()[m_nStartIndex]->EndOfSectionNode())), 
true);
+    SwDoc::CorrAbs(del, del, 
SwPosition(*rDoc.GetNodes()[m_nStartIndex]->EndOfSectionNode(), 
SwNodeOffset(0)), true);
     rDoc.GetNodes().Delete(del);
     if (m_pTitleSectionUpdated)
     {
diff --git a/sw/source/core/undo/untbl.cxx b/sw/source/core/undo/untbl.cxx
index 9bca1f566ddf..dce56d05f3df 100644
--- a/sw/source/core/undo/untbl.cxx
+++ b/sw/source/core/undo/untbl.cxx
@@ -313,7 +313,7 @@ void SwUndoInsTable::RedoImpl(::sw::UndoRedoContext & 
rContext)
 {
     SwDoc & rDoc = rContext.GetDoc();
 
-    SwPosition const aPos(SwNodeIndex(rDoc.GetNodes(), m_nStartNode));
+    SwPosition const aPos(rDoc.GetNodes(), m_nStartNode);
     const SwTable* pTable = rDoc.InsertTable( m_aInsTableOptions, aPos, 
m_nRows, m_nColumns,
                                             m_nAdjust,
                                             m_pAutoFormat.get(), 
m_pColumnWidth.get() );
@@ -2717,7 +2717,7 @@ std::unique_ptr<SwUndo> 
SwUndoTableCpyTable::PrepareRedline( SwDoc* pDoc, const
         if( pText )
             aDeleteStart.nContent.Assign( pText, 0 );
     }
-    SwPosition aCellEnd( SwNodeIndex( *rBox.GetSttNd()->EndOfSectionNode(), -1 
) );
+    SwPosition aCellEnd( *rBox.GetSttNd()->EndOfSectionNode(), 
SwNodeOffset(-1) );
     pText = aCellEnd.nNode.GetNode().GetTextNode();
     if( pText )
         aCellEnd.nContent.Assign(pText, pText->GetText().getLength());
@@ -2729,12 +2729,11 @@ std::unique_ptr<SwUndo> 
SwUndoTableCpyTable::PrepareRedline( SwDoc* pDoc, const
     }
     else if( !rJoin ) // If the old part is empty and joined, we are finished
     {   // if it is not joined, we have to delete this empty paragraph
-        aCellEnd = SwPosition(
-            SwNodeIndex( *rBox.GetSttNd()->EndOfSectionNode() ));
+        aCellEnd = SwPosition(*rBox.GetSttNd()->EndOfSectionNode(), 
SwNodeOffset(0));
         SwPaM aTmpPam( aDeleteStart, aCellEnd );
         pUndo = std::make_unique<SwUndoDelete>(aTmpPam, 
SwDeleteFlags::Default, true);
     }
-    SwPosition aCellStart( SwNodeIndex( *rBox.GetSttNd(), 2 ) );
+    SwPosition aCellStart( *rBox.GetSttNd(), SwNodeOffset(2) );
     pText = aCellStart.nNode.GetNode().GetTextNode();
     if( pText )
         aCellStart.nContent.Assign( pText, 0 );
diff --git a/sw/source/core/unocore/unotext.cxx 
b/sw/source/core/unocore/unotext.cxx
index ae0faed8c1be..bcef9e4db57c 100644
--- a/sw/source/core/unocore/unotext.cxx
+++ b/sw/source/core/unocore/unotext.cxx
@@ -1256,8 +1256,7 @@ SwXText::Impl::finishOrAppendParagraph(
     // find end node, go backward - don't skip tables because the new
     // paragraph has to be the last node
     //aPam.Move( fnMoveBackward, GoInNode );
-    SwPosition aInsertPosition(
-            SwNodeIndex( *pStartNode->EndOfSectionNode(), -1 ) );
+    SwPosition aInsertPosition( *pStartNode->EndOfSectionNode(), 
SwNodeOffset(-1) );
     SwPaM aPam(aInsertPosition);
     // If we got a position reference, then the insert point is not the end of
     // the document.
@@ -2381,7 +2380,7 @@ SwXText::copyText(
         if (!pFirstNode)
         {   // the node at rPos was split; get rid of the first empty one so
             // that the pasted table is first
-            auto 
pDelCursor(m_pImpl->m_pDoc->CreateUnoCursor(SwPosition(SwNodeIndex(*GetStartNode(),
 1))));
+            auto 
pDelCursor(m_pImpl->m_pDoc->CreateUnoCursor(SwPosition(*GetStartNode(), 
SwNodeOffset(1))));
             
m_pImpl->m_pDoc->getIDocumentContentOperations().DelFullPara(*pDelCursor);
         }
     }
diff --git a/sw/source/filter/ww8/writerhelper.cxx 
b/sw/source/filter/ww8/writerhelper.cxx
index 9c3bae38f14d..eabaeb91a79e 100644
--- a/sw/source/filter/ww8/writerhelper.cxx
+++ b/sw/source/filter/ww8/writerhelper.cxx
@@ -117,8 +117,7 @@ namespace
             {
                 // the anchor position will be invalidated by SetRedlineFlags
                 // so set a dummy position and fix it in UpdateFramePositions
-                SwPosition const dummy(SwNodeIndex(
-                            const_cast<SwNodes&>(pAnchor->nNode.GetNodes())));
+                SwPosition const 
dummy(const_cast<SwNodes&>(pAnchor->nNode.GetNodes()));
                 aRet.emplace_back(rEntry, dummy);
             }
             else
@@ -812,7 +811,7 @@ namespace sw
                 // the point node may be deleted in AppendRedline, so park
                 // the PaM somewhere safe
                 aRegion.DeleteMark();
-                *aRegion.GetPoint() = 
SwPosition(SwNodeIndex(mrDoc.GetNodes()));
+                *aRegion.GetPoint() = SwPosition(mrDoc.GetNodes());
                 mrDoc.getIDocumentRedlineAccess().AppendRedline(pNewRedline, 
true);
                 
mrDoc.getIDocumentRedlineAccess().SetRedlineFlags(RedlineFlags::NONE | 
RedlineFlags::ShowInsert |
                      RedlineFlags::ShowDelete );

Reply via email to