configmgr/source/valueparser.cxx | 7 +++---- oox/source/export/chartexport.cxx | 6 ++---- sc/source/core/opencl/opbase.cxx | 7 ++----- sc/source/filter/html/htmlpars.cxx | 3 +-- sfx2/source/control/shell.cxx | 3 +-- svx/source/dialog/framelinkarray.cxx | 6 +++--- sw/source/filter/html/svxcss1.cxx | 8 +++----- sw/source/filter/ww8/rtfexport.cxx | 10 ++++------ 8 files changed, 19 insertions(+), 31 deletions(-)
New commits: commit a33922e38b87db5b009986324c6543e90f18a752 Author: Noel Grandin <noelgran...@gmail.com> AuthorDate: Wed Apr 26 08:41:23 2023 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Fri Apr 28 08:23:04 2023 +0200 optimise find/insert calls to maps Instead of doing two lookups, we can just call insert and then update the mapped-to value if the insert actually succeeded. Change-Id: I3df3b98f0debe6bf74c739dd5850e7714d9c2789 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151030 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/configmgr/source/valueparser.cxx b/configmgr/source/valueparser.cxx index 82778e6c823b..17174368d59b 100644 --- a/configmgr/source/valueparser.cxx +++ b/configmgr/source/valueparser.cxx @@ -352,12 +352,11 @@ bool ValueParser::endElement() { case Node::KIND_LOCALIZED_PROPERTY: { NodeMap & members = node_->getMembers(); - NodeMap::iterator i(members.find(localizedName_)); + auto [i, bInserted] = members.insert(NodeMap::value_type(localizedName_, nullptr)); LocalizedValueNode *pLVNode; - if (i == members.end()) { + if (bInserted) { pLVNode = new LocalizedValueNode(layer_); - members.insert( - NodeMap::value_type(localizedName_, pLVNode )); + i->second = pLVNode; } else { pLVNode = static_cast< LocalizedValueNode * >(i->second.get()); } diff --git a/oox/source/export/chartexport.cxx b/oox/source/export/chartexport.cxx index a2c30f2e8861..94f956428d19 100644 --- a/oox/source/export/chartexport.cxx +++ b/oox/source/export/chartexport.cxx @@ -3345,10 +3345,8 @@ void ChartExport::_exportAxis( } // only export each axis only once non-deleted - bool bDeleted = maExportedAxis.find(rAxisIdPair.nAxisType) != maExportedAxis.end(); - - if (!bDeleted) - maExportedAxis.insert(rAxisIdPair.nAxisType); + auto aItInsertedPair = maExportedAxis.insert(rAxisIdPair.nAxisType); + bool bDeleted = !aItInsertedPair.second; pFS->singleElement(FSNS(XML_c, XML_delete), XML_val, !bDeleted && bVisible ? "0" : "1"); diff --git a/sc/source/core/opencl/opbase.cxx b/sc/source/core/opencl/opbase.cxx index 199b24b32459..4ea248daaa3a 100644 --- a/sc/source/core/opencl/opbase.cxx +++ b/sc/source/core/opencl/opbase.cxx @@ -114,12 +114,9 @@ int DynamicKernelArgument::GetStringId( const rtl_uString* string ) return 0; if( stringIdsMap == nullptr ) stringIdsMap = new std::unordered_map<const rtl_uString*, int>; - std::unordered_map<const rtl_uString*, int>::iterator it = stringIdsMap->find( string ); - if( it != stringIdsMap->end()) - return it->second; int newId = stringIdsMap->size() + 1; - stringIdsMap->insert( std::pair( string, newId )); - return newId; + auto aItInsertedPair = stringIdsMap->insert( std::pair( string, newId )); + return aItInsertedPair.first->second; } void DynamicKernelArgument::ClearStringIds() diff --git a/sc/source/filter/html/htmlpars.cxx b/sc/source/filter/html/htmlpars.cxx index e49920eb563b..db7bfc432a86 100644 --- a/sc/source/filter/html/htmlpars.cxx +++ b/sc/source/filter/html/htmlpars.cxx @@ -768,8 +768,7 @@ void ScHTMLLayoutParser::SetWidths() for (auto it = pLocalColOffset->begin(); it != pLocalColOffset->end(); ++it) { // Only exact offsets, do not use MakeColNoRef(). - if (maColOffset.find(*it) == maColOffset.end()) - maColOffset.insert(*it); + maColOffset.insert(*it); } } } diff --git a/sfx2/source/control/shell.cxx b/sfx2/source/control/shell.cxx index 5bbeb01d92cd..84828b0eff25 100644 --- a/sfx2/source/control/shell.cxx +++ b/sfx2/source/control/shell.cxx @@ -170,8 +170,7 @@ void SfxShell::PutItem if (it != pImpl->m_Items.end()) { // Replace Item - pImpl->m_Items.erase( it ); - pImpl->m_Items.insert(std::make_pair(nWhich, std::unique_ptr<SfxPoolItem>(pItem))); + it->second = std::unique_ptr<SfxPoolItem>(pItem); // if active, notify Bindings SfxDispatcher *pDispat = GetDispatcher(); diff --git a/svx/source/dialog/framelinkarray.cxx b/svx/source/dialog/framelinkarray.cxx index 322e2225d5e6..918aa76dc7ae 100644 --- a/svx/source/dialog/framelinkarray.cxx +++ b/svx/source/dialog/framelinkarray.cxx @@ -1379,10 +1379,10 @@ drawinglayer::primitive2d::Primitive2DContainer Array::CreateB2DPrimitiveRange( GetMergedRange(nColLeft, nRowTop, nColRight, nRowBottom, nCol, nRow); const sal_Int32 nIndexOfMergedCell(mxImpl->GetIndex(nColLeft, nRowTop)); - if(aMergedCells.end() == aMergedCells.find(nIndexOfMergedCell)) + auto aItInsertedPair = aMergedCells.insert(nIndexOfMergedCell); + if(aItInsertedPair.second) { - // not found, so not yet handled. Add now to mark as handled - aMergedCells.insert(nIndexOfMergedCell); + // not found, so not yet handled. // Get and check if diagonal styles are used // Note: For GetCellStyleBLTR below I tried to use nRowBottom diff --git a/sw/source/filter/html/svxcss1.cxx b/sw/source/filter/html/svxcss1.cxx index c50d7312b76f..d53c0a0484f9 100644 --- a/sw/source/filter/html/svxcss1.cxx +++ b/sw/source/filter/html/svxcss1.cxx @@ -925,11 +925,9 @@ void SvxCSS1Parser::InsertMapEntry( const OUString& rKey, const SvxCSS1PropertyInfo& rProp, CSS1Map& rMap ) { - CSS1Map::iterator itr = rMap.find(rKey); - if (itr == rMap.end()) - { - rMap.insert(std::make_pair(rKey, std::make_unique<SvxCSS1MapEntry>(rItemSet, rProp))); - } + auto [itr,inserted] = rMap.insert(std::make_pair(rKey, nullptr)); + if (inserted) + itr->second = std::make_unique<SvxCSS1MapEntry>(rItemSet, rProp); else { SvxCSS1MapEntry *const p = itr->second.get(); diff --git a/sw/source/filter/ww8/rtfexport.cxx b/sw/source/filter/ww8/rtfexport.cxx index 4b78a464c7c5..1bfc2ebc5740 100644 --- a/sw/source/filter/ww8/rtfexport.cxx +++ b/sw/source/filter/ww8/rtfexport.cxx @@ -1432,13 +1432,11 @@ OString* RtfExport::GetStyle(sal_uInt16 nId) sal_uInt16 RtfExport::GetRedline(const OUString& rAuthor) { - auto it = m_aRedlineTable.find(rAuthor); - if (it != m_aRedlineTable.end()) - return it->second; - const sal_uInt16 nId = m_aRedlineTable.size(); - m_aRedlineTable.insert(std::pair<OUString, sal_uInt16>(rAuthor, nId)); - return nId; + // insert if we don't already have one + auto[it, inserted] = m_aRedlineTable.insert(std::pair<OUString, sal_uInt16>(rAuthor, nId)); + (void)inserted; + return it->second; } const OUString* RtfExport::GetRedline(sal_uInt16 nId)