summaryrefslogtreecommitdiff
path: root/sw/source/filter/ww8
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2019-04-17 15:19:25 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2019-04-20 08:02:25 +0200
commitec7ba61a6164c805f5a71b077715b7e1521a2d62 (patch)
tree4d4f3fb1ad960465897754601b0842c78db564bf /sw/source/filter/ww8
parent7d58f26bf4dbeb4e138c2a91f039d8bc7fa00f0c (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')
-rw-r--r--sw/source/filter/ww8/rtfexport.cxx48
-rw-r--r--sw/source/filter/ww8/wrtw8sty.cxx12
-rw-r--r--sw/source/filter/ww8/wrtww8.cxx10
3 files changed, 27 insertions, 43 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)
diff --git a/sw/source/filter/ww8/wrtw8sty.cxx b/sw/source/filter/ww8/wrtw8sty.cxx
index e4e24952f763..8725e7474278 100644
--- a/sw/source/filter/ww8/wrtw8sty.cxx
+++ b/sw/source/filter/ww8/wrtw8sty.cxx
@@ -867,15 +867,11 @@ void wwFontHelper::InitFontTable(const SwDoc& rDoc)
const sal_uInt16 aTypes[] = { RES_CHRATR_FONT, RES_CHRATR_CJK_FONT, RES_CHRATR_CTL_FONT, 0 };
for (const sal_uInt16* pId = aTypes; *pId; ++pId)
{
- sal_uInt32 const nMaxItem = rPool.GetItemCount2( *pId );
- for (sal_uInt32 nGet = 0; nGet < nMaxItem; ++nGet)
+ for (const SfxPoolItem* pItem : rPool.GetItemSurrogates(*pId))
{
- pFont = static_cast<const SvxFontItem*>(rPool.GetItem2( *pId, nGet ));
- if (nullptr != pFont)
- {
- GetId(wwFont(pFont->GetFamilyName(), pFont->GetPitch(),
- pFont->GetFamily(), pFont->GetCharSet()));
- }
+ pFont = static_cast<const SvxFontItem*>(pItem);
+ GetId(wwFont(pFont->GetFamilyName(), pFont->GetPitch(),
+ pFont->GetFamily(), pFont->GetCharSet()));
}
}
}
diff --git a/sw/source/filter/ww8/wrtww8.cxx b/sw/source/filter/ww8/wrtww8.cxx
index 5b66db607afb..07ba40b373fd 100644
--- a/sw/source/filter/ww8/wrtww8.cxx
+++ b/sw/source/filter/ww8/wrtww8.cxx
@@ -3086,10 +3086,9 @@ void MSWordExportBase::AddLinkTarget(const OUString& rURL)
void MSWordExportBase::CollectOutlineBookmarks(const SwDoc &rDoc)
{
- sal_uInt32 nMaxItems = rDoc.GetAttrPool().GetItemCount2(RES_TXTATR_INETFMT);
- for (sal_uInt32 n = 0; n < nMaxItems; ++n)
+ for (const SfxPoolItem* pItem : rDoc.GetAttrPool().GetItemSurrogates(RES_TXTATR_INETFMT))
{
- const SwFormatINetFormat* pINetFormat = rDoc.GetAttrPool().GetItem2(RES_TXTATR_INETFMT, n);
+ auto pINetFormat = dynamic_cast<const SwFormatINetFormat*>(pItem);
if (!pINetFormat)
continue;
@@ -3107,10 +3106,9 @@ void MSWordExportBase::CollectOutlineBookmarks(const SwDoc &rDoc)
AddLinkTarget( pINetFormat->GetValue() );
}
- nMaxItems = rDoc.GetAttrPool().GetItemCount2( RES_URL );
- for (sal_uInt32 n = 0; n < nMaxItems; ++n)
+ for (const SfxPoolItem* pItem : rDoc.GetAttrPool().GetItemSurrogates(RES_URL))
{
- const SwFormatURL *pURL = rDoc.GetAttrPool().GetItem2(RES_URL, n);
+ auto pURL = dynamic_cast<const SwFormatURL*>(pItem);
if (!pURL)
continue;