sw/source/core/doc/DocumentLinksAdministrationManager.cxx |   20 +++++++-------
 sw/source/core/docnode/section.cxx                        |   20 +++++++-------
 sw/source/core/inc/DocumentLinksAdministrationManager.hxx |    3 +-
 3 files changed, 22 insertions(+), 21 deletions(-)

New commits:
commit d624c870943647a9896e45f1aeed7a1862ddbd8a
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Fri Aug 12 09:46:09 2022 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Fri Aug 12 21:31:50 2022 +0200

    can store this SwNodeRange on the stack
    
    Change-Id: Ic3e985fc67dcfef7f9fd59c185e1223258123896
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138194
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/sw/source/core/doc/DocumentLinksAdministrationManager.cxx 
b/sw/source/core/doc/DocumentLinksAdministrationManager.cxx
index 4aa07130b804..0dd65076f71c 100644
--- a/sw/source/core/doc/DocumentLinksAdministrationManager.cxx
+++ b/sw/source/core/doc/DocumentLinksAdministrationManager.cxx
@@ -443,11 +443,11 @@ 
DocumentLinksAdministrationManager::~DocumentLinksAdministrationManager()
 {
 }
 
-bool DocumentLinksAdministrationManager::SelectServerObj( std::u16string_view 
rStr, SwPaM*& rpPam, std::unique_ptr<SwNodeRange>& rpRange ) const
+bool DocumentLinksAdministrationManager::SelectServerObj( std::u16string_view 
rStr, SwPaM*& rpPam, std::optional<SwNodeRange>& roRange ) const
 {
     // Do we actually have the Item?
     rpPam = nullptr;
-    rpRange = nullptr;
+    roRange.reset();
 
     OUString sItem( INetURLObject::decode( rStr,
                                          
INetURLObject::DecodeMechanism::WithCharset ));
@@ -477,8 +477,8 @@ bool DocumentLinksAdministrationManager::SelectServerObj( 
std::u16string_view rS
             }
             if( aPara.pTableNd )
             {
-                rpRange.reset(new SwNodeRange( *aPara.pTableNd, 
SwNodeOffset(0),
-                                *aPara.pTableNd->EndOfSectionNode(), 
SwNodeOffset(1) ));
+                roRange.emplace( *aPara.pTableNd, SwNodeOffset(0),
+                                 *aPara.pTableNd->EndOfSectionNode(), 
SwNodeOffset(1) );
                 return true;
             }
         }
@@ -493,7 +493,7 @@ bool DocumentLinksAdministrationManager::SelectServerObj( 
std::u16string_view rS
                     SwNode* pNd = &pIdx->GetNode();
                     if( !pNd->IsNoTextNode() )
                     {
-                        rpRange.reset(new SwNodeRange( *pNd, SwNodeOffset(1), 
*pNd->EndOfSectionNode() ));
+                        roRange.emplace( *pNd, SwNodeOffset(1), 
*pNd->EndOfSectionNode() );
                         return true;
                     }
                 }
@@ -515,7 +515,7 @@ bool DocumentLinksAdministrationManager::SelectServerObj( 
std::u16string_view rS
                 const SwOutlineNodes& rOutlNds = 
m_rDoc.GetNodes().GetOutLineNds();
                 SwOutlineNodes::size_type nTmpPos;
                 (void)rOutlNds.Seek_Entry( pNd, &nTmpPos );
-                rpRange.reset(new SwNodeRange( aPos.nNode, SwNodeOffset(0), 
aPos.nNode ));
+                roRange.emplace( aPos.nNode, SwNodeOffset(0), aPos.nNode );
 
                 // look for the section's end, now
                 for( ++nTmpPos;
@@ -526,9 +526,9 @@ bool DocumentLinksAdministrationManager::SelectServerObj( 
std::u16string_view rS
                     ;       // there is no block
 
                 if( nTmpPos < rOutlNds.size() )
-                    rpRange->aEnd = *rOutlNds[ nTmpPos ];
+                    roRange->aEnd = *rOutlNds[ nTmpPos ];
                 else
-                    rpRange->aEnd = m_rDoc.GetNodes().GetEndOfContent();
+                    roRange->aEnd = m_rDoc.GetNodes().GetEndOfContent();
                 return true;
             }
         }
@@ -562,8 +562,8 @@ bool DocumentLinksAdministrationManager::SelectServerObj( 
std::u16string_view rS
             }
             if( aPara.pSectNd )
             {
-                rpRange.reset(new SwNodeRange( *aPara.pSectNd, SwNodeOffset(1),
-                                        *aPara.pSectNd->EndOfSectionNode() ));
+                roRange.emplace( *aPara.pSectNd, SwNodeOffset(1),
+                                 *aPara.pSectNd->EndOfSectionNode() );
                 return true;
 
             }
diff --git a/sw/source/core/docnode/section.cxx 
b/sw/source/core/docnode/section.cxx
index 96f448b3d0f5..ad3049b10dcb 100644
--- a/sw/source/core/docnode/section.cxx
+++ b/sw/source/core/docnode/section.cxx
@@ -1199,7 +1199,7 @@ static void lcl_UpdateLinksInSect( const SwBaseLink& 
rUpdLnk, SwSectionNode& rSe
                 rSection.SetConnectFlag();
 
                 SwNodeIndex aSave( pPam->GetPoint()->nNode, -1 );
-                std::unique_ptr<SwNodeRange> pCpyRg;
+                std::optional<SwNodeRange> oCpyRg;
 
                 if( xDocSh->GetMedium() &&
                     rSection.GetLinkFilePassword().isEmpty() )
@@ -1230,7 +1230,7 @@ static void lcl_UpdateLinksInSect( const SwBaseLink& 
rUpdLnk, SwSectionNode& rSe
 
                     SwPaM* pCpyPam = nullptr;
                     if( !bRecursion &&
-                        
pSrcDoc->GetDocumentLinksAdministrationManager().SelectServerObj( sRange, 
pCpyPam, pCpyRg )
+                        
pSrcDoc->GetDocumentLinksAdministrationManager().SelectServerObj( sRange, 
pCpyPam, oCpyRg )
                         && pCpyPam )
                     {
                         if( pSrcDoc != pDoc ||
@@ -1241,15 +1241,15 @@ static void lcl_UpdateLinksInSect( const SwBaseLink& 
rUpdLnk, SwSectionNode& rSe
                         }
                         delete pCpyPam;
                     }
-                    if( pCpyRg && pSrcDoc == pDoc &&
-                        pCpyRg->aStart < rInsPos && rInsPos < pCpyRg->aEnd )
+                    if( oCpyRg && pSrcDoc == pDoc &&
+                        oCpyRg->aStart < rInsPos && rInsPos < oCpyRg->aEnd )
                     {
-                        pCpyRg.reset();
+                        oCpyRg.reset();
                     }
                 }
                 else if( pSrcDoc != pDoc )
-                    pCpyRg.reset(new SwNodeRange( 
pSrcDoc->GetNodes().GetEndOfExtras(), SwNodeOffset(2),
-                                          
pSrcDoc->GetNodes().GetEndOfContent() ));
+                    oCpyRg.emplace( pSrcDoc->GetNodes().GetEndOfExtras(), 
SwNodeOffset(2),
+                                          
pSrcDoc->GetNodes().GetEndOfContent() );
 
                 // #i81653#
                 // Update links of extern linked document or extern linked
@@ -1260,7 +1260,7 @@ static void lcl_UpdateLinksInSect( const SwBaseLink& 
rUpdLnk, SwSectionNode& rSe
                     
pSrcDoc->getIDocumentLinksAdministration().GetLinkManager().UpdateAllLinks( 
false, false, nullptr );
                 }
 
-                if( pCpyRg )
+                if( oCpyRg )
                 {
                     SwNodeIndex& rInsPos = pPam->GetPoint()->nNode;
                     bool bCreateFrame = rInsPos.GetIndex() <=
@@ -1269,7 +1269,7 @@ static void lcl_UpdateLinksInSect( const SwBaseLink& 
rUpdLnk, SwSectionNode& rSe
 
                     SwTableNumFormatMerge aTNFM( *pSrcDoc, *pDoc );
 
-                    
pSrcDoc->GetDocumentContentOperationsManager().CopyWithFlyInFly(*pCpyRg, 
rInsPos, nullptr, bCreateFrame);
+                    
pSrcDoc->GetDocumentContentOperationsManager().CopyWithFlyInFly(*oCpyRg, 
rInsPos, nullptr, bCreateFrame);
                     ++aSave;
 
                     if( !bCreateFrame )
@@ -1286,7 +1286,7 @@ static void lcl_UpdateLinksInSect( const SwBaseLink& 
rUpdLnk, SwSectionNode& rSe
                         pDoc->CorrAbs( aSave, *pPam->GetPoint(), 0, true );
                         pDoc->GetNodes().Delete( aSave );
                     }
-                    pCpyRg.reset();
+                    oCpyRg.reset();
                 }
 
                 lcl_BreakSectionLinksInSect( *pSectNd );
diff --git a/sw/source/core/inc/DocumentLinksAdministrationManager.hxx 
b/sw/source/core/inc/DocumentLinksAdministrationManager.hxx
index e03d969d211b..28dcd7544a4b 100644
--- a/sw/source/core/inc/DocumentLinksAdministrationManager.hxx
+++ b/sw/source/core/inc/DocumentLinksAdministrationManager.hxx
@@ -23,6 +23,7 @@
 #include <IDocumentLinksAdministration.hxx>
 
 #include <memory>
+#include <optional>
 #include <string_view>
 
 namespace sfx2 { class LinkManager; }
@@ -62,7 +63,7 @@ public:
     bool LinksUpdated() const override;
 
     //Non-Interface method
-    bool SelectServerObj( std::u16string_view rStr, SwPaM*& rpPam, 
std::unique_ptr<SwNodeRange>& rpRange ) const;
+    bool SelectServerObj( std::u16string_view rStr, SwPaM*& rpPam, 
std::optional<SwNodeRange>& rpRange ) const;
 
     virtual ~DocumentLinksAdministrationManager() override;
 

Reply via email to