sw/inc/fmtpdsc.hxx               |    4 +++-
 sw/source/core/layout/atrfrm.cxx |   12 +++++++++++-
 2 files changed, 14 insertions(+), 2 deletions(-)

New commits:
commit a111a1eff73b141c28b5ab87715eed62696f91a3
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Fri Aug 23 09:57:12 2024 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Fri Aug 23 14:29:47 2024 +0200

    tdf#158556 make SwFormatPageDesc hashable
    
    Change-Id: I609c63ec22c94ce9d5ccc10e9608787c5189937b
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/172305
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>
    Tested-by: Jenkins

diff --git a/sw/inc/fmtpdsc.hxx b/sw/inc/fmtpdsc.hxx
index 81aaaddf6048..e72181468439 100644
--- a/sw/inc/fmtpdsc.hxx
+++ b/sw/inc/fmtpdsc.hxx
@@ -51,6 +51,8 @@ public:
 
     /// "Pure virtual methods" of SfxPoolItem.
     virtual bool            operator==( const SfxPoolItem& ) const override;
+    virtual bool            supportsHashCode() const override { return true; }
+    virtual size_t          hashCode() const override;
     virtual SwFormatPageDesc* Clone( SfxItemPool* pPool = nullptr ) const 
override;
     virtual bool GetPresentation( SfxItemPresentation ePres,
                                   MapUnit eCoreMetric,
@@ -64,7 +66,7 @@ public:
     const SwPageDesc *GetPageDesc() const { return static_cast<const 
SwPageDesc*>(GetRegisteredIn()); }
 
     const ::std::optional<sal_uInt16>&  GetNumOffset() const        { return 
m_oNumOffset; }
-    void    SetNumOffset( const ::std::optional<sal_uInt16>& oNum ) { 
m_oNumOffset = oNum; }
+    void    SetNumOffset( const ::std::optional<sal_uInt16>& oNum ) { 
ASSERT_CHANGE_REFCOUNTED_ITEM; m_oNumOffset = oNum; }
 
     /// Query / set where attribute is anchored.
     const sw::BroadcastingModify* GetDefinedIn() const { return m_pDefinedIn; }
diff --git a/sw/source/core/layout/atrfrm.cxx b/sw/source/core/layout/atrfrm.cxx
index 84e9a59d6e6e..128fc74aa629 100644
--- a/sw/source/core/layout/atrfrm.cxx
+++ b/sw/source/core/layout/atrfrm.cxx
@@ -672,7 +672,7 @@ SwFormatPageDesc &SwFormatPageDesc::operator=(const 
SwFormatPageDesc &rCpy)
 {
     if (SfxPoolItem::areSame(*this, rCpy))
         return *this;
-
+    ASSERT_CHANGE_REFCOUNTED_ITEM;
     if (rCpy.GetPageDesc())
         RegisterToPageDesc(*const_cast<SwPageDesc*>(rCpy.GetPageDesc()));
     m_oNumOffset = rCpy.m_oNumOffset;
@@ -696,6 +696,15 @@ bool SwFormatPageDesc::operator==( const SfxPoolItem& 
rAttr ) const
             ( GetPageDesc() == static_cast<const 
SwFormatPageDesc&>(rAttr).GetPageDesc() );
 }
 
+size_t SwFormatPageDesc::hashCode() const
+{
+    std::size_t seed(0);
+    // note that we cannot include m_pDefinedIn in the hash because that is 
updated in SwAttrSet::SetModifyAtAttr
+    o3tl::hash_combine(seed, m_oNumOffset);
+    o3tl::hash_combine(seed, GetPageDesc());
+    return seed;
+}
+
 SwFormatPageDesc* SwFormatPageDesc::Clone( SfxItemPool* ) const
 {
     return new SwFormatPageDesc( *this );
@@ -789,6 +798,7 @@ bool SwFormatPageDesc::QueryValue( uno::Any& rVal, 
sal_uInt8 nMemberId ) const
 
 bool SwFormatPageDesc::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
 {
+    ASSERT_CHANGE_REFCOUNTED_ITEM;
     // here we convert always!
     nMemberId &= ~CONVERT_TWIPS;
     bool bRet = true;

Reply via email to