diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2019-04-17 15:19:25 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2019-04-20 08:02:25 +0200 |
commit | ec7ba61a6164c805f5a71b077715b7e1521a2d62 (patch) | |
tree | 4d4f3fb1ad960465897754601b0842c78db564bf /sw/source/filter/ww8/rtfexport.cxx | |
parent | 7d58f26bf4dbeb4e138c2a91f039d8bc7fa00f0c (diff) |
simplify SfxPoolItemArray_Impl (tdf#81765 related)
Since we want to look up items by pointer, just store them in a
std::unordered_set, which allows fast find().
This dramatically simplifies most operations on this data structure.
Fix a dodgy sd test that was relying on items with the same whichid
being in the pool being in a certain order.
Change-Id: I4d79fc718f95e3083a20788be1050fbe9fca7263
Reviewed-on: https://gerrit.libreoffice.org/70881
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sw/source/filter/ww8/rtfexport.cxx')
-rw-r--r-- | sw/source/filter/ww8/rtfexport.cxx | 48 |
1 files changed, 19 insertions, 29 deletions
diff --git a/sw/source/filter/ww8/rtfexport.cxx b/sw/source/filter/ww8/rtfexport.cxx index 494c26c2dafa..b2b06a77443b 100644 --- a/sw/source/filter/ww8/rtfexport.cxx +++ b/sw/source/filter/ww8/rtfexport.cxx @@ -747,10 +747,9 @@ ErrCode RtfExport::ExportDocument_Impl() // protected section in the document. { const SfxItemPool& rPool = m_pDoc->GetAttrPool(); - sal_uInt32 const nMaxItem = rPool.GetItemCount2(RES_PROTECT); - for (sal_uInt32 n = 0; n < nMaxItem; ++n) + for (const SfxPoolItem* pItem2 : rPool.GetItemSurrogates(RES_PROTECT)) { - auto pProtect = rPool.GetItem2(RES_PROTECT, n); + auto pProtect = dynamic_cast<const SvxProtectItem*>(pItem2); if (pProtect && pProtect->IsContentProtected()) { Strm().WriteCharPtr(OOO_STRING_SVTOOLS_RTF_FORMPROT); @@ -1182,7 +1181,6 @@ void RtfExport::OutColorTable() { // Build the table from rPool since the colors provided to // RtfAttributeOutput callbacks are too late. - sal_uInt32 nMaxItem; const SfxItemPool& rPool = m_pDoc->GetAttrPool(); // MSO Word uses a default color table with 16 colors (which is used e.g. for highlighting) @@ -1209,28 +1207,25 @@ void RtfExport::OutColorTable() InsColor(pCol->GetValue()); if ((pCol = rPool.GetPoolDefaultItem(RES_CHRATR_COLOR))) InsColor(pCol->GetValue()); - nMaxItem = rPool.GetItemCount2(RES_CHRATR_COLOR); - for (sal_uInt32 n = 0; n < nMaxItem; ++n) + for (const SfxPoolItem* pItem : rPool.GetItemSurrogates(RES_CHRATR_COLOR)) { - if ((pCol = rPool.GetItem2(RES_CHRATR_COLOR, n))) + if ((pCol = dynamic_cast<const SvxColorItem*>(pItem))) InsColor(pCol->GetValue()); } auto pUnder = GetDfltAttr(RES_CHRATR_UNDERLINE); InsColor(pUnder->GetColor()); - nMaxItem = rPool.GetItemCount2(RES_CHRATR_UNDERLINE); - for (sal_uInt32 n = 0; n < nMaxItem; ++n) + for (const SfxPoolItem* pItem : rPool.GetItemSurrogates(RES_CHRATR_UNDERLINE)) { - if ((pUnder = rPool.GetItem2(RES_CHRATR_UNDERLINE, n))) + if ((pUnder = dynamic_cast<const SvxUnderlineItem*>(pItem))) InsColor(pUnder->GetColor()); } auto pOver = GetDfltAttr(RES_CHRATR_OVERLINE); InsColor(pOver->GetColor()); - nMaxItem = rPool.GetItemCount2(RES_CHRATR_OVERLINE); - for (sal_uInt32 n = 0; n < nMaxItem; ++n) + for (const SfxPoolItem* pItem : rPool.GetItemSurrogates(RES_CHRATR_OVERLINE)) { - if ((pOver = rPool.GetItem2(RES_CHRATR_OVERLINE, n))) + if ((pOver = dynamic_cast<const SvxOverlineItem*>(pItem))) InsColor(pOver->GetColor()); } } @@ -1246,10 +1241,9 @@ void RtfExport::OutColorTable() { InsColor(pBackground->GetColor()); } - nMaxItem = rPool.GetItemCount2(*pIds); - for (sal_uInt32 n = 0; n < nMaxItem; ++n) + for (const SfxPoolItem* pItem : rPool.GetItemSurrogates(*pIds)) { - if ((pBackground = static_cast<const SvxBrushItem*>(rPool.GetItem2(*pIds, n)))) + if ((pBackground = static_cast<const SvxBrushItem*>(pItem))) { InsColor(pBackground->GetColor()); } @@ -1264,10 +1258,9 @@ void RtfExport::OutColorTable() { InsColor(pShadow->GetColor()); } - nMaxItem = rPool.GetItemCount2(RES_SHADOW); - for (sal_uInt32 n = 0; n < nMaxItem; ++n) + for (const SfxPoolItem* pItem : rPool.GetItemSurrogates(RES_SHADOW)) { - if (nullptr != (pShadow = rPool.GetItem2(RES_SHADOW, n))) + if ((pShadow = dynamic_cast<const SvxShadowItem*>(pItem))) { InsColor(pShadow->GetColor()); } @@ -1279,10 +1272,9 @@ void RtfExport::OutColorTable() const SvxBoxItem* pBox; if (nullptr != (pBox = rPool.GetPoolDefaultItem(RES_BOX))) InsColorLine(*pBox); - nMaxItem = rPool.GetItemCount2(RES_BOX); - for (sal_uInt32 n = 0; n < nMaxItem; ++n) + for (const SfxPoolItem* pItem : rPool.GetItemSurrogates(RES_BOX)) { - if (nullptr != (pBox = rPool.GetItem2(RES_BOX, n))) + if ((pBox = dynamic_cast<const SvxBoxItem*>(pItem))) InsColorLine(*pBox); } } @@ -1291,20 +1283,18 @@ void RtfExport::OutColorTable() const SvxBoxItem* pCharBox; if ((pCharBox = rPool.GetPoolDefaultItem(RES_CHRATR_BOX))) InsColorLine(*pCharBox); - nMaxItem = rPool.GetItemCount2(RES_CHRATR_BOX); - for (sal_uInt32 n = 0; n < nMaxItem; ++n) + for (const SfxPoolItem* pItem : rPool.GetItemSurrogates(RES_CHRATR_BOX)) { - if ((pCharBox = rPool.GetItem2(RES_CHRATR_BOX, n))) + if ((pCharBox = dynamic_cast<const SvxBoxItem*>(pItem))) InsColorLine(*pCharBox); } } // TextFrame or paragraph background solid fill. - nMaxItem = rPool.GetItemCount2(XATTR_FILLCOLOR); - for (sal_uInt32 i = 0; i < nMaxItem; ++i) + for (const SfxPoolItem* pItem : rPool.GetItemSurrogates(XATTR_FILLCOLOR)) { - if (auto pItem = rPool.GetItem2(XATTR_FILLCOLOR, i)) - InsColor(pItem->GetColorValue()); + if (auto pColorItem = dynamic_cast<const XFillColorItem*>(pItem)) + InsColor(pColorItem->GetColorValue()); } for (std::size_t n = 0; n < m_aColTable.size(); ++n) |