sw/inc/fmtcntnt.hxx              |    6 +++---
 sw/source/core/layout/atrfrm.cxx |   23 +++++++++++------------
 2 files changed, 14 insertions(+), 15 deletions(-)

New commits:
commit 77a8d0d06573cd095863904d34dc7a0ca131cf1a
Author:     Noel Grandin <noelgran...@gmail.com>
AuthorDate: Mon Aug 8 15:31:20 2022 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Wed Aug 10 10:50:32 2022 +0200

    unique_ptr->optional in SwFormatContent
    
    Change-Id: I815fa0f2dcdc1512958d95703b56449010fd2f6e
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138075
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/sw/inc/fmtcntnt.hxx b/sw/inc/fmtcntnt.hxx
index f579dd1c1676..3765e0a2e4a0 100644
--- a/sw/inc/fmtcntnt.hxx
+++ b/sw/inc/fmtcntnt.hxx
@@ -23,14 +23,14 @@
 #include <svl/poolitem.hxx>
 #include "hintids.hxx"
 #include "format.hxx"
+#include "ndindex.hxx"
 
-class SwNodeIndex;
 class SwStartNode;
 
 /// Content, content of frame (header, footer, fly).
 class SAL_DLLPUBLIC_RTTI SwFormatContent final : public SfxPoolItem
 {
-    std::unique_ptr<SwNodeIndex> m_pStartNode;
+    std::optional<SwNodeIndex> m_oStartNode;
 
     SwFormatContent &operator=( const SwFormatContent & ) = delete;
 
@@ -43,7 +43,7 @@ public:
     virtual bool            operator==( const SfxPoolItem& ) const override;
     virtual SwFormatContent* Clone( SfxItemPool* pPool = nullptr ) const 
override;
 
-    const SwNodeIndex *GetContentIdx() const { return m_pStartNode.get(); }
+    const SwNodeIndex *GetContentIdx() const { return m_oStartNode ? 
&*m_oStartNode : nullptr; }
     void SetNewContentIdx( const SwNodeIndex *pIdx );
 
     void dumpAsXml(xmlTextWriterPtr pWriter) const override;
diff --git a/sw/source/core/layout/atrfrm.cxx b/sw/source/core/layout/atrfrm.cxx
index 9da40280f0d9..841a0f8f918e 100644
--- a/sw/source/core/layout/atrfrm.cxx
+++ b/sw/source/core/layout/atrfrm.cxx
@@ -578,15 +578,15 @@ SwFormatFooter* SwFormatFooter::Clone( SfxItemPool* ) 
const
 // Partially implemented inline in hxx
 SwFormatContent::SwFormatContent( const SwFormatContent &rCpy )
     : SfxPoolItem( RES_CNTNT )
+    , m_oStartNode( rCpy.m_oStartNode )
 {
-    m_pStartNode.reset( rCpy.GetContentIdx() ?
-                      new SwNodeIndex( *rCpy.GetContentIdx() ) : nullptr);
 }
 
 SwFormatContent::SwFormatContent( const SwStartNode *pStartNd )
     : SfxPoolItem( RES_CNTNT )
 {
-    m_pStartNode.reset( pStartNd ? new SwNodeIndex( *pStartNd ) : nullptr);
+    if (pStartNd)
+        m_oStartNode = *pStartNd;
 }
 
 SwFormatContent::~SwFormatContent()
@@ -595,17 +595,16 @@ SwFormatContent::~SwFormatContent()
 
 void SwFormatContent::SetNewContentIdx( const SwNodeIndex *pIdx )
 {
-    m_pStartNode.reset( pIdx ? new SwNodeIndex( *pIdx ) : nullptr );
+    if (pIdx)
+        m_oStartNode = *pIdx;
+    else
+        m_oStartNode.reset();
 }
 
 bool SwFormatContent::operator==( const SfxPoolItem& rAttr ) const
 {
     assert(SfxPoolItem::operator==(rAttr));
-    if( static_cast<bool>(m_pStartNode) != static_cast<bool>(static_cast<const 
SwFormatContent&>(rAttr).m_pStartNode) )
-        return false;
-    if( m_pStartNode )
-        return ( *m_pStartNode == *static_cast<const 
SwFormatContent&>(rAttr).GetContentIdx() );
-    return true;
+    return m_oStartNode == static_cast<const 
SwFormatContent&>(rAttr).m_oStartNode;
 }
 
 SwFormatContent* SwFormatContent::Clone( SfxItemPool* ) const
@@ -617,13 +616,13 @@ void SwFormatContent::dumpAsXml(xmlTextWriterPtr pWriter) 
const
 {
     (void)xmlTextWriterStartElement(pWriter, BAD_CAST("SwFormatContent"));
     (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("whichId"), 
BAD_CAST(OString::number(Which()).getStr()));
-    if (m_pStartNode)
+    if (m_oStartNode)
     {
         (void)xmlTextWriterWriteAttribute(
             pWriter, BAD_CAST("startNode"),
-            
BAD_CAST(OString::number(sal_Int32(m_pStartNode->GetNode().GetIndex())).getStr()));
+            
BAD_CAST(OString::number(sal_Int32(m_oStartNode->GetNode().GetIndex())).getStr()));
         (void)xmlTextWriterWriteFormatAttribute(pWriter, 
BAD_CAST("startNodePtr"), "%p",
-                                          &m_pStartNode->GetNode());
+                                          &m_oStartNode->GetNode());
     }
     (void)xmlTextWriterEndElement(pWriter);
 }

Reply via email to