sw/inc/doc.hxx                  |    3 ++
 sw/source/core/bastyp/init.cxx  |    2 -
 sw/source/core/doc/doc.cxx      |   12 +++++++++
 sw/source/filter/xml/xmlexp.cxx |   51 ++++++++++++++++++++++++----------------
 4 files changed, 47 insertions(+), 21 deletions(-)

New commits:
commit 809808f56bc79c229ca7ce84eb03274271ff1044
Author:     Noel Grandin <noelgran...@gmail.com>
AuthorDate: Fri Sep 20 16:47:23 2024 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Sat Sep 21 13:13:59 2024 +0200

    dont use GetItemSurrogates for gathering SvXMLAttrContainerItem
    
    which is very expensive these days
    
    Change-Id: I1880ae272e422baca7b0540f58c9e8f9c3bb1287
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/173732
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/sw/inc/doc.hxx b/sw/inc/doc.hxx
index 0e16a9607e34..7137078c1571 100644
--- a/sw/inc/doc.hxx
+++ b/sw/inc/doc.hxx
@@ -1461,6 +1461,9 @@ public:
     /// Iterate over all RES_PARATR_TABSTOP SvxTabStopItem, if the function 
returns false, iteration is stopped
     SW_DLLPUBLIC void ForEachParaAtrTabStopItem(const std::function<bool(const 
SvxTabStopItem&)>&  ) const;
 
+    /// Iterate over all RES_UNKNOWNATR_CONTAINER SvXMLAttrContainerItem, if 
the function returns false, iteration is stopped
+    SW_DLLPUBLIC void ForEachUnknownAtrContainerItem(const 
std::function<bool(const SvXMLAttrContainerItem&)>&  ) const;
+
     // Call into intransparent Basic; expect possible Return String.
     void ExecMacro( const SvxMacro& rMacro, OUString* pRet, SbxArray* pArgs );
 
diff --git a/sw/source/core/bastyp/init.cxx b/sw/source/core/bastyp/init.cxx
index 9c1fb0bb62c5..487484512141 100644
--- a/sw/source/core/bastyp/init.cxx
+++ b/sw/source/core/bastyp/init.cxx
@@ -457,7 +457,7 @@ ItemInfoPackage& getItemInfoPackageSwAttributes()
             { RES_BOXATR_FORMAT, new SwTableBoxNumFormat, 0, 
SFX_ITEMINFOFLAG_NONE },
             { RES_BOXATR_FORMULA, new SwTableBoxFormula( OUString() ), 0, 
SFX_ITEMINFOFLAG_NONE },
             { RES_BOXATR_VALUE, new SwTableBoxValue, 0, SFX_ITEMINFOFLAG_NONE 
},
-            { RES_UNKNOWNATR_CONTAINER, new SvXMLAttrContainerItem( 
RES_UNKNOWNATR_CONTAINER ), 0, SFX_ITEMINFOFLAG_SUPPORT_SURROGATE }
+            { RES_UNKNOWNATR_CONTAINER, new SvXMLAttrContainerItem( 
RES_UNKNOWNATR_CONTAINER ), 0, SFX_ITEMINFOFLAG_NONE }
         }};
 
         virtual const ItemInfoStatic& getItemInfoStatic(size_t nIndex) const 
override { return maItemInfos[nIndex]; }
diff --git a/sw/source/core/doc/doc.cxx b/sw/source/core/doc/doc.cxx
index 1f2db1ab6668..15e6a1bf29fe 100644
--- a/sw/source/core/doc/doc.cxx
+++ b/sw/source/core/doc/doc.cxx
@@ -1533,6 +1533,18 @@ void SwDoc::ForEachParaAtrTabStopItem(const 
std::function<bool(const SvxTabStopI
     }
 }
 
+/// Iterate over all RES_UNKNOWNATR_CONTAINER SvXMLAttrContainerItem, if the 
function returns false, iteration is stopped
+void SwDoc::ForEachUnknownAtrContainerItem(const std::function<bool(const 
SvXMLAttrContainerItem&)>& rFunc ) const
+{
+    for(SwFrameFormat* pFormat : *GetFrameFormats())
+    {
+        const SwAttrSet& rAttrSet = pFormat->GetAttrSet();
+        if (const SvXMLAttrContainerItem* pItem = 
rAttrSet.GetItemIfSet(RES_UNKNOWNATR_CONTAINER))
+            if (!rFunc(*pItem))
+                return;
+    }
+}
+
 void SwDoc::Summary(SwDoc& rExtDoc, sal_uInt8 nLevel, sal_uInt8 nPara, bool 
bImpress)
 {
     const SwOutlineNodes& rOutNds = GetNodes().GetOutLineNds();
diff --git a/sw/source/filter/xml/xmlexp.cxx b/sw/source/filter/xml/xmlexp.cxx
index 0d9e89979bdf..676317ef869e 100644
--- a/sw/source/filter/xml/xmlexp.cxx
+++ b/sw/source/filter/xml/xmlexp.cxx
@@ -148,31 +148,42 @@ ErrCode SwXMLExport::exportDoc( enum XMLTokenEnum eClass )
             }
             return true;
         });
-
+        pDoc->ForEachUnknownAtrContainerItem([this](const 
SvXMLAttrContainerItem& rUnknown) -> bool {
+            if( rUnknown.GetAttrCount() > 0 )
+            {
+                sal_uInt16 nIdx = rUnknown.GetFirstNamespaceIndex();
+                while( USHRT_MAX != nIdx )
+                {
+                    GetNamespaceMap_().Add( rUnknown.GetPrefix( nIdx ),
+                                        rUnknown.GetNamespace( nIdx ) );
+                    nIdx = rUnknown.GetNextNamespaceIndex( nIdx );
+                }
+            }
+            return true;
+        });
         const SfxItemPool& rPool = pDoc->GetAttrPool();
-        sal_uInt16 aWhichIds[4] = { RES_UNKNOWNATR_CONTAINER,
-                                    SDRATTR_XMLATTRIBUTES,
-                                    EE_PARA_XMLATTRIBS,
-                                    EE_CHAR_XMLATTRIBS };
-
-        const int nWhichIds = rPool.GetSecondaryPool() ? 4 : 1;
-        for( int j=0; j < nWhichIds; ++j )
+        if (rPool.GetSecondaryPool())
         {
-            const sal_uInt16 nWhichId = aWhichIds[j];
-            ItemSurrogates aSurrogates;
-            rPool.GetItemSurrogates(aSurrogates, nWhichId);
-            for (const SfxPoolItem* pItem : aSurrogates)
+            sal_uInt16 aWhichIds[3] = { SDRATTR_XMLATTRIBUTES,
+                                        EE_PARA_XMLATTRIBS,
+                                        EE_CHAR_XMLATTRIBS };
+            for( sal_uInt16 nWhichId : aWhichIds )
             {
-                auto pUnknown = dynamic_cast<const SvXMLAttrContainerItem*>( 
pItem  );
-                OSL_ENSURE( pUnknown, "illegal attribute container item" );
-                if( pUnknown && (pUnknown->GetAttrCount() > 0) )
+                ItemSurrogates aSurrogates;
+                rPool.GetItemSurrogates(aSurrogates, nWhichId);
+                for (const SfxPoolItem* pItem : aSurrogates)
                 {
-                    sal_uInt16 nIdx = pUnknown->GetFirstNamespaceIndex();
-                    while( USHRT_MAX != nIdx )
+                    auto pUnknown = dynamic_cast<const 
SvXMLAttrContainerItem*>( pItem  );
+                    OSL_ENSURE( pUnknown, "illegal attribute container item" );
+                    if( pUnknown && (pUnknown->GetAttrCount() > 0) )
                     {
-                        GetNamespaceMap_().Add( pUnknown->GetPrefix( nIdx ),
-                                            pUnknown->GetNamespace( nIdx ) );
-                        nIdx = pUnknown->GetNextNamespaceIndex( nIdx );
+                        sal_uInt16 nIdx = pUnknown->GetFirstNamespaceIndex();
+                        while( USHRT_MAX != nIdx )
+                        {
+                            GetNamespaceMap_().Add( pUnknown->GetPrefix( nIdx 
),
+                                                pUnknown->GetNamespace( nIdx ) 
);
+                            nIdx = pUnknown->GetNextNamespaceIndex( nIdx );
+                        }
                     }
                 }
             }

Reply via email to