diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2019-04-18 15:13:19 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2019-04-19 13:19:31 +0200 |
commit | 1a5b12aa5da2c718848d3cc5d9bce7bfcdeacf54 (patch) | |
tree | 25044edc2afb99073ba6bef8d181dadbb6a53467 /framework | |
parent | eaaaad0e21edb27edaa865eee03696f007cd8010 (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 'framework')
-rw-r--r-- | framework/source/uielement/toolbarmanager.cxx | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/framework/source/uielement/toolbarmanager.cxx b/framework/source/uielement/toolbarmanager.cxx index 20d1222e552c..abaface6e133 100644 --- a/framework/source/uielement/toolbarmanager.cxx +++ b/framework/source/uielement/toolbarmanager.cxx @@ -1042,16 +1042,14 @@ void ToolBarManager::FillToolbar( const Reference< XIndexAccess >& rItemContaine // Fill command map. It stores all our commands and from what // image manager we got our image. So we can decide if we have to use an // image from a notification message. - CommandToInfoMap::iterator pIter = m_aCommandMap.find( aCommandURL ); - if ( pIter == m_aCommandMap.end()) + auto pIter = m_aCommandMap.emplace( aCommandURL, aCmdInfo ); + if ( pIter.second ) { aCmdInfo.nId = nId; - const CommandToInfoMap::value_type aValue( aCommandURL, aCmdInfo ); - m_aCommandMap.insert( aValue ); } else { - pIter->second.aIds.push_back( nId ); + pIter.first->second.aIds.push_back( nId ); } if ( !bIsVisible ) @@ -1197,16 +1195,15 @@ void ToolBarManager::FillOverflowToolbar( ToolBox const * pParent ) // Fill command map. It stores all our commands and from what // image manager we got our image. So we can decide if we have to use an // image from a notification message. - CommandToInfoMap::iterator pIter = m_aCommandMap.find( aCommandURL ); - if ( pIter == m_aCommandMap.end()) + auto pIter = m_aCommandMap.emplace( aCommandURL, aCmdInfo ); + if ( pIter.second ) { aCmdInfo.nId = nId; const CommandToInfoMap::value_type aValue( aCommandURL, aCmdInfo ); - m_aCommandMap.insert( aValue ); } else { - pIter->second.aIds.push_back( nId ); + pIter.first->second.aIds.push_back( nId ); } } else |