diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2015-01-18 21:17:03 +0100 |
---|---|---|
committer | Michael Stahl <mstahl@redhat.com> | 2015-01-19 22:51:02 +0000 |
commit | 0657176b3e42886c4ae14f9991c52b4d61bbe116 (patch) | |
tree | 01eec29ba6df3851657563d8a3359997420c9238 | |
parent | e15e4d3888c1ebd229acd8e676d28115edf622e3 (diff) |
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@redhat.com>
Reviewed-by: Michael Stahl <mstahl@redhat.com>
-rw-r--r-- | sw/source/core/doc/textboxhelper.cxx | 31 |
1 files changed, 26 insertions, 5 deletions
diff --git a/sw/source/core/doc/textboxhelper.cxx b/sw/source/core/doc/textboxhelper.cxx index e05123436299..a6525ba6e6dd 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) |