diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2024-03-20 09:59:09 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2024-03-21 08:39:46 +0100 |
commit | 241e2d68664e0e53cf02fe9986462c4a9ecd8d42 (patch) | |
tree | 4f5558b24f747dc5fb1e65e3c7270db425d46db8 | |
parent | 4656674fa7daaf6eca13613e31d32382e755fe4d (diff) |
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.grandin@collabora.co.uk>
-rw-r--r-- | sw/inc/doc.hxx | 1 | ||||
-rw-r--r-- | sw/source/core/doc/docfly.cxx | 19 | ||||
-rw-r--r-- | sw/source/core/unocore/unoframe.cxx | 13 |
3 files changed, 21 insertions, 12 deletions
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; |