sw/source/core/docnode/node.cxx   |   26 +++++++++++++--------
 sw/source/core/fields/docufld.cxx |   46 +++++++++++++++++++++-----------------
 2 files changed, 42 insertions(+), 30 deletions(-)

New commits:
commit d54ef79c77fa6537d86850434c1bb6ef5f9b292a
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Fri Jul 19 18:18:26 2024 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Fri Jul 19 21:26:14 2024 +0200

    don't use GetItemSurrogates in SwNode::FindPageDesc
    
    They are quite slow, and we want to reduce usage of them
    
    Change-Id: Idae1d6035942d29d67269a22b2a771616ea836af
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/170775
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/sw/source/core/docnode/node.cxx b/sw/source/core/docnode/node.cxx
index a7edb3a7e6ac..3f1ebd5b72d4 100644
--- a/sw/source/core/docnode/node.cxx
+++ b/sw/source/core/docnode/node.cxx
@@ -696,18 +696,24 @@ const SwPageDesc* SwNode::FindPageDesc( SwNodeOffset* 
pPgDescNdIdx ) const
         {
             SwFindNearestNode aInfo( *pNd );
             // Over all Nodes of all PageDescs
-            ItemSurrogates aSurrogates;
-            rDoc.GetAttrPool().GetItemSurrogates(aSurrogates, RES_PAGEDESC);
-            for (const SfxPoolItem* pItem : aSurrogates)
+            for (SwRootFrame* pRootFrame : 
const_cast<SwDoc&>(rDoc).GetAllLayouts())
             {
-                auto pPageDescItem = dynamic_cast<const 
SwFormatPageDesc*>(pItem);
-                if( pPageDescItem && pPageDescItem->GetDefinedIn() )
+                const SwPageFrame* pPageFrameIter = pRootFrame->GetLastPage();
+                while (pPageFrameIter)
                 {
-                    const sw::BroadcastingModify* pMod = 
pPageDescItem->GetDefinedIn();
-                    if( auto pContentNode = dynamic_cast<const 
SwContentNode*>( pMod) )
-                        aInfo.CheckNode( *pContentNode );
-                    else if( auto pFormat = dynamic_cast<const SwFormat*>( 
pMod) )
-                        pFormat->GetInfo( aInfo );
+                    const SwContentFrame* pContentFrame = 
pPageFrameIter->FindFirstBodyContent();
+                    if (pContentFrame)
+                    {
+                        const SwFormatPageDesc& rFormatPageDesc = 
pContentFrame->GetPageDescItem();
+                        if ( const sw::BroadcastingModify* pMod = 
rFormatPageDesc.GetDefinedIn() )
+                        {
+                            if( auto pContentNode = dynamic_cast<const 
SwContentNode*>( pMod) )
+                                aInfo.CheckNode( *pContentNode );
+                            else if( auto pFormat = dynamic_cast<const 
SwFormat*>( pMod) )
+                                pFormat->GetInfo( aInfo );
+                        }
+                    }
+                    pPageFrameIter = static_cast<const 
SwPageFrame*>(pPageFrameIter->GetPrev());
                 }
             }
 
commit dd18aed100405dff88b881c9c8c3e8cf88553dfe
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Fri Jul 19 16:11:19 2024 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Fri Jul 19 21:26:05 2024 +0200

    don't use GetItemSurrogates in SwPageNumberFieldType::ChangeExpansion
    
    They are quite slow, and we want to reduce usage of them
    
    Change-Id: I5ab3b55e9270419877a08dd1d711ba2fa757a1b5
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/170774
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>
    Tested-by: Jenkins

diff --git a/sw/source/core/fields/docufld.cxx 
b/sw/source/core/fields/docufld.cxx
index 17fbb40a31f0..2e5056b6bbaa 100644
--- a/sw/source/core/fields/docufld.cxx
+++ b/sw/source/core/fields/docufld.cxx
@@ -140,30 +140,36 @@ void SwPageNumberFieldType::ChangeExpansion( SwDoc* pDoc,
         return;
 
     // check the flag since the layout NEVER sets it back
-    const SfxItemPool &rPool = pDoc->GetAttrPool();
-    ItemSurrogates aSurrogates;
-    rPool.GetItemSurrogates(aSurrogates, RES_PAGEDESC);
-    for (const SfxPoolItem* pItem : aSurrogates)
+    for (SwRootFrame* pRootFrame : pDoc->GetAllLayouts())
     {
-        auto pDesc = dynamic_cast<const SwFormatPageDesc*>(pItem);
-        if( pDesc && pDesc->GetNumOffset() && pDesc->GetDefinedIn() )
+        const SwPageFrame* pPageFrameIter = pRootFrame->GetLastPage();
+        while (pPageFrameIter)
         {
-            const SwContentNode* pNd = dynamic_cast<const SwContentNode*>( 
pDesc->GetDefinedIn()  );
-            if( pNd )
+            const SwContentFrame* pContentFrame = 
pPageFrameIter->FindFirstBodyContent();
+            if (pContentFrame)
             {
-                if (SwIterator<SwFrame, SwContentNode, 
sw::IteratorMode::UnwrapMulti>(*pNd).First())
-                // sw_redlinehide: not sure if this should happen only if
-                // it's the first node, because that's where RES_PAGEDESC
-                // is effective?
-                    m_bVirtual = true;
-            }
-            else if( dynamic_cast< const SwFormat* >(pDesc->GetDefinedIn()) != 
 nullptr)
-            {
-                m_bVirtual = false;
-                sw::AutoFormatUsedHint aHint(m_bVirtual, pDoc->GetNodes());
-                pDesc->GetDefinedIn()->CallSwClientNotify(aHint);
-                break;
+                const SwFormatPageDesc& rFormatPageDesc = 
pContentFrame->GetPageDescItem();
+                if ( rFormatPageDesc.GetNumOffset() && 
rFormatPageDesc.GetDefinedIn() )
+                {
+                    const SwContentNode* pNd = dynamic_cast<const 
SwContentNode*>( rFormatPageDesc.GetDefinedIn()  );
+                    if( pNd )
+                    {
+                        if (SwIterator<SwFrame, SwContentNode, 
sw::IteratorMode::UnwrapMulti>(*pNd).First())
+                        // sw_redlinehide: not sure if this should happen only 
if
+                        // it's the first node, because that's where 
RES_PAGEDESC
+                        // is effective?
+                            m_bVirtual = true;
+                    }
+                    else if( dynamic_cast< const SwFormat* 
>(rFormatPageDesc.GetDefinedIn()) !=  nullptr)
+                    {
+                        m_bVirtual = false;
+                        sw::AutoFormatUsedHint aHint(m_bVirtual, 
pDoc->GetNodes());
+                        
rFormatPageDesc.GetDefinedIn()->CallSwClientNotify(aHint);
+                        break;
+                    }
+                }
             }
+            pPageFrameIter = static_cast<const 
SwPageFrame*>(pPageFrameIter->GetPrev());
         }
     }
 }

Reply via email to