sw/inc/doc.hxx                      |    1 +
 sw/source/core/doc/docfly.cxx       |   19 +++++++++++++++++++
 sw/source/core/unocore/unoframe.cxx |   13 +------------
 3 files changed, 21 insertions(+), 12 deletions(-)

New commits:
commit 241e2d68664e0e53cf02fe9986462c4a9ecd8d42
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Wed Mar 20 09:59:09 2024 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Thu Mar 21 08:39:46 2024 +0100

    tdf#158556 speedup docx load
    
    Avoid O(n^2) loop in SwXFrame::setPropertyValue, we even have an index
    to search for this stuff
    
    Reduces load time from 325s to 172s
    
    Change-Id: I6c6c03206ef81be1d7d7702a4313acd23d75442d
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/165044
    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 e359cb0ba293..5dc62530454a 100644
--- a/sw/inc/doc.hxx
+++ b/sw/inc/doc.hxx
@@ -838,6 +838,7 @@ public:
     SW_DLLPUBLIC std::vector<SwFrameFormat const*> GetFlyFrameFormats(
             FlyCntType eType,
             bool bIgnoreTextBoxes);
+    SwFrameFormat* GetFlyFrameFormatByName( const OUString& sFrameFormatName );
 
     // Copy formats in own arrays and return them.
     SwFrameFormat  *CopyFrameFormat ( const SwFrameFormat& );
diff --git a/sw/source/core/doc/docfly.cxx b/sw/source/core/doc/docfly.cxx
index c492212487c3..203894123007 100644
--- a/sw/source/core/doc/docfly.cxx
+++ b/sw/source/core/doc/docfly.cxx
@@ -149,6 +149,25 @@ SwFrameFormat* SwDoc::GetFlyNum( size_t nIdx, FlyCntType 
eType, bool bIgnoreText
     return pRetFormat;
 }
 
+SwFrameFormat* SwDoc::GetFlyFrameFormatByName( const OUString& 
rFrameFormatName )
+{
+    auto pFrameFormats = GetSpzFrameFormats();
+    auto it = pFrameFormats->findByTypeAndName( RES_FLYFRMFMT, 
rFrameFormatName );
+    auto endIt = pFrameFormats->typeAndNameEnd();
+    for ( ; it != endIt; ++it)
+    {
+        sw::SpzFrameFormat* pFlyFormat = *it;
+        const SwNodeIndex* pIdx = pFlyFormat->GetContent().GetContentIdx();
+        if( !pIdx || !pIdx->GetNodes().IsDocNodes() )
+            continue;
+
+        const SwNode* pNd = GetNodes()[ pIdx->GetIndex() + 1 ];
+        if( !pNd->IsNoTextNode())
+            return pFlyFormat;
+    }
+    return nullptr;
+}
+
 std::vector<SwFrameFormat const*> SwDoc::GetFlyFrameFormats(
     FlyCntType const eType, bool const bIgnoreTextBoxes)
 {
diff --git a/sw/source/core/unocore/unoframe.cxx 
b/sw/source/core/unocore/unoframe.cxx
index f8509ad4626c..9eb773e7cd50 100644
--- a/sw/source/core/unocore/unoframe.cxx
+++ b/sw/source/core/unocore/unoframe.cxx
@@ -1714,18 +1714,7 @@ void SwXFrame::setPropertyValue(const OUString& 
rPropertyName, const ::uno::Any&
             }
             else
             {
-                const size_t nCount = pDoc->GetFlyCount(FLYCNTTYPE_FRM);
-
-                SwFrameFormat* pChain = nullptr;
-                for( size_t i = 0; i < nCount; ++i )
-                {
-                    SwFrameFormat* pFormat2 = pDoc->GetFlyNum(i, 
FLYCNTTYPE_FRM);
-                    if(sChainName == pFormat2->GetName() )
-                    {
-                        pChain = pFormat2;
-                        break;
-                    }
-                }
+                SwFrameFormat* pChain = 
pDoc->GetFlyFrameFormatByName(sChainName);
                 if(pChain)
                 {
                     SwFrameFormat* pSource = bNextFrame ? pFormat : pChain;

Reply via email to