sw/source/core/frmedt/fefly1.cxx |   21 +++++++--------------
 1 file changed, 7 insertions(+), 14 deletions(-)

New commits:
commit 64aeb5ad0fa2497007c9ee9808f0881bfec99b24
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Wed Mar 20 10:45:35 2024 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Fri Mar 22 07:56:14 2024 +0100

    avoid O(n^2) loop in writer
    
    Change-Id: If82328f1cf9cbd6812f9cad8646c9cf5100314e3
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/165047
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/sw/source/core/frmedt/fefly1.cxx b/sw/source/core/frmedt/fefly1.cxx
index 4529e175afb3..494b08b1c77c 100644
--- a/sw/source/core/frmedt/fefly1.cxx
+++ b/sw/source/core/frmedt/fefly1.cxx
@@ -1939,15 +1939,11 @@ void 
SwFEShell::GetConnectableFrameFormats(SwFrameFormat & rFormat,
     if (pOldChainPrev)
         mxDoc->Unchain(*pOldChainPrev);
 
-    const size_t nCnt = mxDoc->GetFlyCount(FLYCNTTYPE_FRM);
-
     /* potential successors resp. predecessors */
-    std::vector< const SwFrameFormat * > aTmpSpzArray;
+    std::vector<const SwFrameFormat *> aTmpSpzArray = 
mxDoc->GetFlyFrameFormats(FLYCNTTYPE_FRM, false);
 
-    for (size_t n = 0; n < nCnt; ++n)
+    for (auto it = aTmpSpzArray.begin(); it != aTmpSpzArray.end(); ++it)
     {
-        const SwFrameFormat & rFormat1 = *(mxDoc->GetFlyNum(n, 
FLYCNTTYPE_FRM));
-
         /*
            pFormat is a potential successor of rFormat if it is chainable after
            rFormat.
@@ -1959,17 +1955,14 @@ void 
SwFEShell::GetConnectableFrameFormats(SwFrameFormat & rFormat,
         SwChainRet nChainState;
 
         if (bSuccessors)
-            nChainState = mxDoc->Chainable(rFormat, rFormat1);
+            nChainState = mxDoc->Chainable(rFormat, **it);
         else
-            nChainState = mxDoc->Chainable(rFormat1, rFormat);
-
-        if (nChainState == SwChainRet::OK)
-        {
-            aTmpSpzArray.push_back(&rFormat1);
-
-        }
+            nChainState = mxDoc->Chainable(**it, rFormat);
 
+        if (nChainState != SwChainRet::OK)
+            *it = nullptr;
     }
+    std::erase(aTmpSpzArray, nullptr);
 
     if  (!aTmpSpzArray.empty())
     {

Reply via email to