sw/source/core/doc/textboxhelper.cxx | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-)
New commits: commit 0657176b3e42886c4ae14f9991c52b4d61bbe116 Author: Miklos Vajna <vmik...@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 <mst...@redhat.com> Reviewed-by: Michael Stahl <mst...@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) _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits