[Libreoffice-commits] core.git: Branch 'libreoffice-4-4' - sw/source

Miklos Vajna vmiklos at collabora.co.uk
Mon Jan 19 14:51:37 PST 2015


 sw/source/core/doc/textboxhelper.cxx |   31 ++++++++++++++++++++++++++-----
 1 file changed, 26 insertions(+), 5 deletions(-)

New commits:
commit 0657176b3e42886c4ae14f9991c52b4d61bbe116
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Sun Jan 18 21:17:03 2015 +0100

    fdo#84714 SwTextBoxHelper::findTextBoxes: optimize unnecessary O(n^2)
    
    (cherry picked from commit 8d758d0764beb78a49f3035c254eb085b112c2b1)
    
    Change-Id: Ib127b6cf44a69709673465db99cc79417b18c266
    Reviewed-on: https://gerrit.libreoffice.org/14015
    Tested-by: Michael Stahl <mstahl at redhat.com>
    Reviewed-by: Michael Stahl <mstahl at redhat.com>

diff --git a/sw/source/core/doc/textboxhelper.cxx b/sw/source/core/doc/textboxhelper.cxx
index e051234..a6525ba 100644
--- a/sw/source/core/doc/textboxhelper.cxx
+++ b/sw/source/core/doc/textboxhelper.cxx
@@ -117,17 +117,38 @@ void SwTextBoxHelper::destroy(SwFrmFmt* pShape)
 
 std::set<const SwFrmFmt*> SwTextBoxHelper::findTextBoxes(const SwDoc* pDoc)
 {
-    std::set<const SwFrmFmt*> aRet;
+    std::set<const SwFrmFmt*> aTextBoxes;
+    std::map<SwNodeIndex, const SwFrmFmt*> aFlyFormats, aDrawFormats;
 
     const SwFrmFmts& rSpzFrmFmts = *pDoc->GetSpzFrmFmts();
     for (SwFrmFmts::const_iterator it = rSpzFrmFmts.begin(); it != rSpzFrmFmts.end(); ++it)
     {
-        SwFrmFmt* pTextBox = findTextBox(*it);
-        if (pTextBox)
-            aRet.insert(pTextBox);
+        const SwFrmFmt* pFormat = *it;
+
+        // A TextBox in the context of this class is a fly frame that has a
+        // matching (same RES_CNTNT) draw frame.
+        if (!pFormat->GetAttrSet().HasItem(RES_CNTNT) || !pFormat->GetCntnt().GetCntntIdx())
+            continue;
+
+        const SwNodeIndex& rIndex = *pFormat->GetCntnt().GetCntntIdx();
+
+        if (pFormat->Which() == RES_FLYFRMFMT)
+        {
+            if (aDrawFormats.find(rIndex) != aDrawFormats.end())
+                aTextBoxes.insert(pFormat);
+            else
+                aFlyFormats[rIndex] = pFormat;
+        }
+        else if (pFormat->Which() == RES_DRAWFRMFMT)
+        {
+            if (aFlyFormats.find(rIndex) != aFlyFormats.end())
+                aTextBoxes.insert(aFlyFormats[rIndex]);
+            else
+                aDrawFormats[rIndex] = pFormat;
+        }
     }
 
-    return aRet;
+    return aTextBoxes;
 }
 
 std::set<const SwFrmFmt*> SwTextBoxHelper::findTextBoxes(const SwNode& rNode)


More information about the Libreoffice-commits mailing list