summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2019-04-18 15:13:19 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2019-04-19 13:19:31 +0200
commit1a5b12aa5da2c718848d3cc5d9bce7bfcdeacf54 (patch)
tree25044edc2afb99073ba6bef8d181dadbb6a53467 /sw
parenteaaaad0e21edb27edaa865eee03696f007cd8010 (diff)
optimise find/insert pattern
if we're doing a find/insert on a set or a map, it is better to just do a conditional insert/emplace operation than triggering two lookups. Change-Id: I80da5097f5a89fe30fa348ce5b6e747c34287a8d Reviewed-on: https://gerrit.libreoffice.org/70937 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sw')
-rw-r--r--sw/source/core/crsr/findattr.cxx6
-rw-r--r--sw/source/core/doc/DocumentListItemsManager.cxx6
-rw-r--r--sw/source/core/layout/movedfwdfrmsbyobjpos.cxx7
-rw-r--r--sw/source/core/table/swtable.cxx6
-rw-r--r--sw/source/core/unocore/unocrsrhelper.cxx6
-rw-r--r--sw/source/core/unocore/unostyle.cxx3
-rw-r--r--sw/source/filter/html/htmlforw.cxx10
-rw-r--r--sw/source/filter/ww8/wrtw8sty.cxx6
-rw-r--r--sw/source/filter/ww8/ww8graf2.cxx3
-rw-r--r--sw/source/filter/xml/XMLRedlineImportHelper.cxx10
10 files changed, 18 insertions, 45 deletions
diff --git a/sw/source/core/crsr/findattr.cxx b/sw/source/core/crsr/findattr.cxx
index c115c9b359b9..47a2a1e04266 100644
--- a/sw/source/core/crsr/findattr.cxx
+++ b/sw/source/core/crsr/findattr.cxx
@@ -990,9 +990,8 @@ bool FindAttrImpl(SwPaM & rSearchPam,
if( !pNode->HasSwAttrSet() )
{
SwFormat* pTmpFormat = pNode->GetFormatColl();
- if( aFormatArr.find( pTmpFormat ) != aFormatArr.end() )
+ if( !aFormatArr.insert( pTmpFormat ).second )
continue; // collection was requested earlier
- aFormatArr.insert( pTmpFormat );
}
if( SfxItemState::SET == pNode->GetSwAttrSet().GetItemState( nWhich,
@@ -1165,9 +1164,8 @@ static bool FindAttrsImpl(SwPaM & rSearchPam,
if (!rPropsNode.HasSwAttrSet())
{
SwFormat* pTmpFormat = rPropsNode.GetFormatColl();
- if( aFormatArr.find( pTmpFormat ) != aFormatArr.end() )
+ if( !aFormatArr.insert( pTmpFormat ).second )
continue; // collection was requested earlier
- aFormatArr.insert( pTmpFormat );
}
if (lcl_Search(rPropsNode, aOtherSet, bNoColls))
diff --git a/sw/source/core/doc/DocumentListItemsManager.cxx b/sw/source/core/doc/DocumentListItemsManager.cxx
index d48473003660..6fd3925d9ad6 100644
--- a/sw/source/core/doc/DocumentListItemsManager.cxx
+++ b/sw/source/core/doc/DocumentListItemsManager.cxx
@@ -45,13 +45,9 @@ void DocumentListItemsManager::addListItem( const SwNodeNum& rNodeNum )
}
const bool bAlreadyInserted(
- mpListItemsList->find( &rNodeNum ) != mpListItemsList->end() );
+ mpListItemsList->insert( &rNodeNum ).second );
OSL_ENSURE( !bAlreadyInserted,
"<DocumentListItemsManager::addListItem(..)> - <SwNodeNum> instance already registered as numbered item!" );
- if ( !bAlreadyInserted )
- {
- mpListItemsList->insert( &rNodeNum );
- }
}
void DocumentListItemsManager::removeListItem( const SwNodeNum& rNodeNum )
diff --git a/sw/source/core/layout/movedfwdfrmsbyobjpos.cxx b/sw/source/core/layout/movedfwdfrmsbyobjpos.cxx
index 0ba8984d4765..7585cd25b3e1 100644
--- a/sw/source/core/layout/movedfwdfrmsbyobjpos.cxx
+++ b/sw/source/core/layout/movedfwdfrmsbyobjpos.cxx
@@ -35,12 +35,7 @@ SwMovedFwdFramesByObjPos::~SwMovedFwdFramesByObjPos()
void SwMovedFwdFramesByObjPos::Insert( const SwTextFrame& _rMovedFwdFrameByObjPos,
const sal_uInt32 _nToPageNum )
{
- if ( maMovedFwdFrames.end() ==
- maMovedFwdFrames.find(_rMovedFwdFrameByObjPos.GetTextNodeFirst()) )
- {
- const NodeMapEntry aEntry(_rMovedFwdFrameByObjPos.GetTextNodeFirst(), _nToPageNum);
- maMovedFwdFrames.insert( aEntry );
- }
+ maMovedFwdFrames.emplace(_rMovedFwdFrameByObjPos.GetTextNodeFirst(), _nToPageNum);
}
void SwMovedFwdFramesByObjPos::Remove( const SwTextFrame& _rTextFrame )
diff --git a/sw/source/core/table/swtable.cxx b/sw/source/core/table/swtable.cxx
index eee79e9e8354..337d712d95db 100644
--- a/sw/source/core/table/swtable.cxx
+++ b/sw/source/core/table/swtable.cxx
@@ -2676,12 +2676,10 @@ const SwCellFrame * SwTableCellInfo::Impl::getNextTableBoxsCellFrame(const SwFra
{
const SwCellFrame * pCellFrame = static_cast<const SwCellFrame *>(pFrame);
const SwTableBox * pTabBox = pCellFrame->GetTabBox();
- TableBoxes_t::const_iterator aIt = m_HandledTableBoxes.find(pTabBox);
-
- if (aIt == m_HandledTableBoxes.end())
+ auto aIt = m_HandledTableBoxes.insert(pTabBox);
+ if (aIt.second)
{
pResult = pCellFrame;
- m_HandledTableBoxes.insert(pTabBox);
break;
}
}
diff --git a/sw/source/core/unocore/unocrsrhelper.cxx b/sw/source/core/unocore/unocrsrhelper.cxx
index 61f0f3500c74..d2c57b119166 100644
--- a/sw/source/core/unocore/unocrsrhelper.cxx
+++ b/sw/source/core/unocore/unocrsrhelper.cxx
@@ -1373,11 +1373,7 @@ void makeTableCellRedline( SwTableBox& rTableBox,
void SwAnyMapHelper::SetValue( sal_uInt16 nWhichId, sal_uInt16 nMemberId, const uno::Any& rAny )
{
sal_uInt32 nKey = (nWhichId << 16) + nMemberId;
- auto aIt = m_Map.find( nKey );
- if (aIt != m_Map.end())
- aIt->second = rAny;
- else
- m_Map.insert(std::make_pair(nKey, rAny));
+ m_Map[nKey] = rAny;
}
bool SwAnyMapHelper::FillValue( sal_uInt16 nWhichId, sal_uInt16 nMemberId, const uno::Any*& pAny )
diff --git a/sw/source/core/unocore/unostyle.cxx b/sw/source/core/unocore/unostyle.cxx
index 9c71b4f816ad..95ad63c1af03 100644
--- a/sw/source/core/unocore/unostyle.cxx
+++ b/sw/source/core/unocore/unostyle.cxx
@@ -3747,9 +3747,8 @@ SwAutoStylesEnumImpl::SwAutoStylesEnumImpl( SwDoc* pInitDoc, IStyleAccess::SwAut
if ( pItem && pItem->GetTextRuby() )
{
std::pair< sal_uInt16, text::RubyAdjust > aPair( pItem->GetPosition(), pItem->GetAdjustment() );
- if ( aRubyMap.find( aPair ) == aRubyMap.end() )
+ if ( aRubyMap.insert( aPair ).second )
{
- aRubyMap.insert( aPair );
std::shared_ptr<SfxItemSet> pItemSet( new SfxItemSet( rAttrPool, svl::Items<RES_TXTATR_CJK_RUBY, RES_TXTATR_CJK_RUBY>{} ) );
pItemSet->Put( *pItem );
mAutoStyles.push_back( pItemSet );
diff --git a/sw/source/filter/html/htmlforw.cxx b/sw/source/filter/html/htmlforw.cxx
index 5407ee03a383..3b0715581352 100644
--- a/sw/source/filter/html/htmlforw.cxx
+++ b/sw/source/filter/html/htmlforw.cxx
@@ -1309,13 +1309,11 @@ static void AddControl( HTMLControls& rControls,
{
uno::Reference< container::XIndexContainer > xFormComps( xForm, uno::UNO_QUERY );
std::unique_ptr<HTMLControl> pHCntrl(new HTMLControl( xFormComps, nNodeIdx ));
- HTMLControls::const_iterator it = rControls.find( pHCntrl.get() );
- if( it == rControls.end() )
- rControls.insert( std::move(pHCntrl) );
- else
+ auto itPair = rControls.insert( std::move(pHCntrl) );
+ if (!itPair.second )
{
- if( (*it)->xFormComps==xFormComps )
- (*it)->nCount++;
+ if( (*itPair.first)->xFormComps==xFormComps )
+ (*itPair.first)->nCount++;
}
}
}
diff --git a/sw/source/filter/ww8/wrtw8sty.cxx b/sw/source/filter/ww8/wrtw8sty.cxx
index f7bc5136e922..e4e24952f763 100644
--- a/sw/source/filter/ww8/wrtw8sty.cxx
+++ b/sw/source/filter/ww8/wrtw8sty.cxx
@@ -353,18 +353,16 @@ void MSWordStyles::BuildStyleIds()
OString aLower(aStyleId.toAsciiLowerCase());
// check for uniqueness & construct something unique if we have to
- if (aUsed.find(aLower) == aUsed.end())
+ if (aUsed.insert(aLower).second)
{
- aUsed.insert(aLower);
m_aStyleIds.push_back(aStyleId);
}
else
{
int nFree = 1;
- while (aUsed.find(aLower + OString::number(nFree)) != aUsed.end())
+ while (!aUsed.insert(aLower + OString::number(nFree)).second)
++nFree;
- aUsed.insert(aLower + OString::number(nFree));
m_aStyleIds.emplace_back(aStyleId + OString::number(nFree));
}
}
diff --git a/sw/source/filter/ww8/ww8graf2.cxx b/sw/source/filter/ww8/ww8graf2.cxx
index 94c2036edace..f577ab60d0e1 100644
--- a/sw/source/filter/ww8/ww8graf2.cxx
+++ b/sw/source/filter/ww8/ww8graf2.cxx
@@ -259,9 +259,8 @@ bool SwWW8ImplReader::ReadGrafFile(OUString& rFileName, std::unique_ptr<Graphic>
//skip duplicate graphics when fuzzing
if (utl::ConfigManager::IsFuzzing())
{
- if (m_aGrafPosSet.find(nPosFc) != m_aGrafPosSet.end())
+ if (!m_aGrafPosSet.insert(nPosFc).second)
return false;
- m_aGrafPosSet.insert(nPosFc);
}
if (m_xWwFib->m_envr != 1) // !MAC as creator
diff --git a/sw/source/filter/xml/XMLRedlineImportHelper.cxx b/sw/source/filter/xml/XMLRedlineImportHelper.cxx
index d78e7e6b4849..ee3563c497a1 100644
--- a/sw/source/filter/xml/XMLRedlineImportHelper.cxx
+++ b/sw/source/filter/xml/XMLRedlineImportHelper.cxx
@@ -418,12 +418,8 @@ void XMLRedlineImportHelper::Add(
pInfo->bMergeLastParagraph = bMergeLastPara;
// ad 3)
- if (aRedlineMap.end() == aRedlineMap.find(rId))
- {
- // 3a) insert into map
- aRedlineMap[rId] = pInfo;
- }
- else
+ auto itPair = aRedlineMap.emplace(rId, pInfo);
+ if (!itPair.second)
{
// 3b) we already have a redline with this name: hierarchical redlines
// insert pInfo as last element in the chain.
@@ -431,7 +427,7 @@ void XMLRedlineImportHelper::Add(
// find last element
RedlineInfo* pInfoChain;
- for( pInfoChain = aRedlineMap[rId];
+ for( pInfoChain = itPair.first->second;
nullptr != pInfoChain->pNextRedline;
pInfoChain = pInfoChain->pNextRedline) ; // empty loop