diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2015-01-18 21:17:03 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2015-01-18 21:17:51 +0100 |
commit | 8d758d0764beb78a49f3035c254eb085b112c2b1 (patch) | |
tree | 31fa95d4883a2fd16859722588d81e308570aa07 /sw | |
parent | 80eb001e6a861c68f2915d4eebded5e36e1875f6 (diff) |
SwTextBoxHelper::findTextBoxes: optimize unnecessary O(n^2)
Change-Id: Ib127b6cf44a69709673465db99cc79417b18c266
Diffstat (limited to 'sw')
-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 d447b5b71d29..f5096a0c762b 100644 --- a/sw/source/core/doc/textboxhelper.cxx +++ b/sw/source/core/doc/textboxhelper.cxx @@ -114,17 +114,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) |