diff options
author | Arkadiy Illarionov <qarkai@gmail.com> | 2019-03-10 21:51:45 +0300 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2019-03-12 16:10:01 +0100 |
commit | 95a538180fd21c52b752cbef46acf2aa2b842ab8 (patch) | |
tree | 6b248190da44e68400fbd663dbb17d5fd6c4223d /comphelper | |
parent | f9b354784faf65ecc8024cf6d7d7aaf589f6d91f (diff) |
Simplify containers iterations in chart2, cli_ure, comphelper, configmgr
Use range-based loop or replace with STL functions
Change-Id: I7c229faa96e08b76cb4f182a1bd77c15bac4ba76
Reviewed-on: https://gerrit.libreoffice.org/69010
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'comphelper')
-rw-r--r-- | comphelper/source/container/embeddedobjectcontainer.cxx | 94 | ||||
-rw-r--r-- | comphelper/source/container/enumerablemap.cxx | 13 | ||||
-rw-r--r-- | comphelper/source/container/interfacecontainer2.cxx | 31 | ||||
-rw-r--r-- | comphelper/source/eventattachermgr/eventattachermgr.cxx | 66 | ||||
-rw-r--r-- | comphelper/source/misc/componentmodule.cxx | 15 | ||||
-rw-r--r-- | comphelper/source/misc/docpasswordhelper.cxx | 10 | ||||
-rw-r--r-- | comphelper/source/misc/numberedcollection.cxx | 15 | ||||
-rw-r--r-- | comphelper/source/misc/storagehelper.cxx | 18 | ||||
-rw-r--r-- | comphelper/source/property/propertycontainerhelper.cxx | 23 |
9 files changed, 109 insertions, 176 deletions
diff --git a/comphelper/source/container/embeddedobjectcontainer.cxx b/comphelper/source/container/embeddedobjectcontainer.cxx index c2e61bcc6f72..ffa22966a53b 100644 --- a/comphelper/source/container/embeddedobjectcontainer.cxx +++ b/comphelper/source/container/embeddedobjectcontainer.cxx @@ -434,41 +434,37 @@ void EmbeddedObjectContainer::AddEmbeddedObject( const css::uno::Reference < css // look for object in temporary container if ( pImpl->mpTempObjectContainer ) { - EmbeddedObjectContainerNameMap::iterator aEnd = pImpl->mpTempObjectContainer->pImpl->maObjectContainer.end(); - for( EmbeddedObjectContainerNameMap::iterator aIter = pImpl->mpTempObjectContainer->pImpl->maObjectContainer.begin(); - aIter != aEnd; - ++aIter ) + auto& rObjectContainer = pImpl->mpTempObjectContainer->pImpl->maObjectContainer; + auto aIter = std::find_if(rObjectContainer.begin(), rObjectContainer.end(), + [&xObj](const EmbeddedObjectContainerNameMap::value_type& rEntry) { return rEntry.second == xObj; }); + if (aIter != rObjectContainer.end()) { - if ( aIter->second == xObj ) + // copy replacement image from temporary container (if there is any) + OUString aTempName = aIter->first; + OUString aMediaType; + uno::Reference < io::XInputStream > xStream = pImpl->mpTempObjectContainer->GetGraphicStream( xObj, &aMediaType ); + if ( xStream.is() ) { - // copy replacement image from temporary container (if there is any) - OUString aTempName = aIter->first; - OUString aMediaType; - uno::Reference < io::XInputStream > xStream = pImpl->mpTempObjectContainer->GetGraphicStream( xObj, &aMediaType ); - if ( xStream.is() ) + InsertGraphicStream( xStream, rName, aMediaType ); + xStream = nullptr; + pImpl->mpTempObjectContainer->RemoveGraphicStream( aTempName ); + } + + // remove object from storage of temporary container + uno::Reference < embed::XEmbedPersist > xPersist( xObj, uno::UNO_QUERY ); + if ( xPersist.is() ) + { + try { - InsertGraphicStream( xStream, rName, aMediaType ); - xStream = nullptr; - pImpl->mpTempObjectContainer->RemoveGraphicStream( aTempName ); + pImpl->mpTempObjectContainer->pImpl->mxStorage->removeElement( aTempName ); } - - // remove object from storage of temporary container - uno::Reference < embed::XEmbedPersist > xPersist( xObj, uno::UNO_QUERY ); - if ( xPersist.is() ) + catch (const uno::Exception&) { - try - { - pImpl->mpTempObjectContainer->pImpl->mxStorage->removeElement( aTempName ); - } - catch (const uno::Exception&) - { - } } - - // temp. container needs to forget the object - pImpl->mpTempObjectContainer->pImpl->maObjectContainer.erase( aIter ); - break; } + + // temp. container needs to forget the object + pImpl->mpTempObjectContainer->pImpl->maObjectContainer.erase( aIter ); } } } @@ -960,24 +956,18 @@ bool EmbeddedObjectContainer::RemoveEmbeddedObject( const uno::Reference < embed return false; } - bool bFound = false; - EmbeddedObjectContainerNameMap::iterator aEnd = pImpl->maObjectContainer.end(); - for( EmbeddedObjectContainerNameMap::iterator aIter = pImpl->maObjectContainer.begin(); - aIter != aEnd; - ++aIter ) + auto aIter = std::find_if(pImpl->maObjectContainer.begin(), pImpl->maObjectContainer.end(), + [&xObj](const EmbeddedObjectContainerNameMap::value_type& rEntry) { return rEntry.second == xObj; }); + if (aIter != pImpl->maObjectContainer.end()) { - if ( aIter->second == xObj ) - { - pImpl->maObjectContainer.erase( aIter ); - bFound = true; - uno::Reference < container::XChild > xChild( xObj, uno::UNO_QUERY ); - if ( xChild.is() ) - xChild->setParent( uno::Reference < uno::XInterface >() ); - break; - } + pImpl->maObjectContainer.erase( aIter ); + uno::Reference < container::XChild > xChild( xObj, uno::UNO_QUERY ); + if ( xChild.is() ) + xChild->setParent( uno::Reference < uno::XInterface >() ); } + else + SAL_WARN( "comphelper.container", "Object not found for removal!" ); - SAL_WARN_IF( !bFound,"comphelper.container", "Object not found for removal!" ); if ( xPersist.is() && bKeepToTempStorage ) // #i119941# { // remove replacement image (if there is one) @@ -1007,22 +997,12 @@ void EmbeddedObjectContainer::CloseEmbeddedObject( const uno::Reference < embed: { // disconnect the object from the container and close it if possible - bool bFound = false; - EmbeddedObjectContainerNameMap::iterator aEnd = pImpl->maObjectContainer.end(); - for( EmbeddedObjectContainerNameMap::iterator aIter = pImpl->maObjectContainer.begin(); - aIter != aEnd; - ++aIter ) + auto aIter = std::find_if(pImpl->maObjectContainer.begin(), pImpl->maObjectContainer.end(), + [&xObj](const EmbeddedObjectContainerNameMap::value_type& rEntry) { return rEntry.second == xObj; }); + if (aIter != pImpl->maObjectContainer.end()) { - if ( aIter->second == xObj ) - { - pImpl->maObjectContainer.erase( aIter ); - bFound = true; - break; - } - } + pImpl->maObjectContainer.erase( aIter ); - if ( bFound ) - { uno::Reference < ::util::XCloseable > xClose( xObj, uno::UNO_QUERY ); try { diff --git a/comphelper/source/container/enumerablemap.cxx b/comphelper/source/container/enumerablemap.cxx index eb21b1795834..f17610f13c71 100644 --- a/comphelper/source/container/enumerablemap.cxx +++ b/comphelper/source/container/enumerablemap.cxx @@ -124,16 +124,11 @@ namespace comphelper static void lcl_revokeMapModificationListener( MapData& _mapData, MapEnumerator& _listener ) { - for ( std::vector< MapEnumerator* >::iterator lookup = _mapData.m_aModListeners.begin(); - lookup != _mapData.m_aModListeners.end(); - ++lookup - ) + auto lookup = std::find(_mapData.m_aModListeners.begin(), _mapData.m_aModListeners.end(), &_listener); + if (lookup != _mapData.m_aModListeners.end()) { - if ( *lookup == &_listener ) - { - _mapData.m_aModListeners.erase( lookup ); - return; - } + _mapData.m_aModListeners.erase( lookup ); + return; } OSL_FAIL( "lcl_revokeMapModificationListener: the listener is not registered!" ); } diff --git a/comphelper/source/container/interfacecontainer2.cxx b/comphelper/source/container/interfacecontainer2.cxx index aac2e6213098..f4610d99acf4 100644 --- a/comphelper/source/container/interfacecontainer2.cxx +++ b/comphelper/source/container/interfacecontainer2.cxx @@ -210,30 +210,17 @@ sal_Int32 OInterfaceContainerHelper2::removeInterface( const Reference<XInterfac if( bIsList ) { - sal_Int32 nLen = aData.pAsVector->size(); - sal_Int32 i; - for( i = 0; i < nLen; i++ ) - { - // It is not valid to compare the pointer directly, but it's faster. - if( (*aData.pAsVector)[i].get() == rListener.get() ) - { - aData.pAsVector->erase(aData.pAsVector->begin()+i); - break; - } - } + // It is not valid to compare the pointer directly, but it's faster. + auto it = std::find_if(aData.pAsVector->begin(), aData.pAsVector->end(), + [&rListener](const css::uno::Reference<css::uno::XInterface>& rItem) { + return rItem.get() == rListener.get(); }); // interface not found, use the correct compare method - if( i == nLen ) - { - for( i = 0; i < nLen; i++ ) - { - if( (*aData.pAsVector)[i] == rListener ) - { - aData.pAsVector->erase(aData.pAsVector->begin()+i); - break; - } - } - } + if (it == aData.pAsVector->end()) + it = std::find(aData.pAsVector->begin(), aData.pAsVector->end(), rListener); + + if (it != aData.pAsVector->end()) + aData.pAsVector->erase(it); if( aData.pAsVector->size() == 1 ) { diff --git a/comphelper/source/eventattachermgr/eventattachermgr.cxx b/comphelper/source/eventattachermgr/eventattachermgr.cxx index e613a92258ac..cfa3ad28e2bd 100644 --- a/comphelper/source/eventattachermgr/eventattachermgr.cxx +++ b/comphelper/source/eventattachermgr/eventattachermgr.cxx @@ -464,19 +464,14 @@ void SAL_CALL ImplEventAttacherManager::revokeScriptEvent if (nLastDot != -1) aLstType = aLstType.copy(nLastDot+1); - std::deque< ScriptEventDescriptor >::const_iterator aEvtEnd = aIt->aEventList.end(); - for( std::deque< ScriptEventDescriptor >::iterator aEvtIt = aIt->aEventList.begin(); - aEvtIt != aEvtEnd; - ++aEvtIt ) - { - if( aLstType == aEvtIt->ListenerType && - EventMethod == aEvtIt->EventMethod && - ToRemoveListenerParam == aEvtIt->AddListenerParam ) - { - aIt->aEventList.erase( aEvtIt ); - break; - } - } + auto aEvtIt = std::find_if(aIt->aEventList.begin(), aIt->aEventList.end(), + [&aLstType, &EventMethod, &ToRemoveListenerParam](const ScriptEventDescriptor& rEvent) { + return aLstType == rEvent.ListenerType + && EventMethod == rEvent.EventMethod + && ToRemoveListenerParam == rEvent.AddListenerParam; + }); + if (aEvtIt != aIt->aEventList.end()) + aIt->aEventList.erase( aEvtIt ); for( const auto& rObj : aList ) attach( nIndex, rObj.xTarget, rObj.aHelper ); @@ -562,19 +557,17 @@ void SAL_CALL ImplEventAttacherManager::attach(sal_Int32 nIndex, const Reference return; Sequence<css::script::EventListener> aEvents(aCurrentPosition->aEventList.size()); - std::deque<ScriptEventDescriptor>::iterator itr = aCurrentPosition->aEventList.begin(); - std::deque<ScriptEventDescriptor>::iterator itrEnd = aCurrentPosition->aEventList.end(); css::script::EventListener* p = aEvents.getArray(); size_t i = 0; - for (; itr != itrEnd; ++itr) + for (const auto& rEvent : aCurrentPosition->aEventList) { css::script::EventListener aListener; aListener.AllListener = - new AttacherAllListener_Impl(this, itr->ScriptType, itr->ScriptCode); + new AttacherAllListener_Impl(this, rEvent.ScriptType, rEvent.ScriptCode); aListener.Helper = rCurObj.aHelper; - aListener.ListenerType = itr->ListenerType; - aListener.EventMethod = itr->EventMethod; - aListener.AddListenerParam = itr->AddListenerParam; + aListener.ListenerType = rEvent.ListenerType; + aListener.EventMethod = rEvent.EventMethod; + aListener.AddListenerParam = rEvent.AddListenerParam; p[i++] = aListener; } @@ -598,32 +591,27 @@ void SAL_CALL ImplEventAttacherManager::detach(sal_Int32 nIndex, const Reference throw IllegalArgumentException(); std::deque< AttacherIndex_Impl >::iterator aCurrentPosition = aIndex.begin() + nIndex; - std::deque< AttachedObject_Impl >::iterator aObjEnd = aCurrentPosition->aObjList.end(); - for( std::deque< AttachedObject_Impl >::iterator aObjIt = aCurrentPosition->aObjList.begin(); - aObjIt != aObjEnd; - ++aObjIt ) + auto aObjIt = std::find_if(aCurrentPosition->aObjList.begin(), aCurrentPosition->aObjList.end(), + [&xObject](const AttachedObject_Impl& rObj) { return rObj.xTarget == xObject; }); + if (aObjIt != aCurrentPosition->aObjList.end()) { - if( aObjIt->xTarget == xObject ) + sal_Int32 i = 0; + for( const auto& rEvt : aCurrentPosition->aEventList ) { - sal_Int32 i = 0; - for( const auto& rEvt : aCurrentPosition->aEventList ) + if( aObjIt->aAttachedListenerSeq[i].is() ) { - if( aObjIt->aAttachedListenerSeq[i].is() ) + try + { + xAttacher->removeListener( aObjIt->xTarget, rEvt.ListenerType, + rEvt.AddListenerParam, aObjIt->aAttachedListenerSeq[i] ); + } + catch( Exception& ) { - try - { - xAttacher->removeListener( aObjIt->xTarget, rEvt.ListenerType, - rEvt.AddListenerParam, aObjIt->aAttachedListenerSeq[i] ); - } - catch( Exception& ) - { - } } - ++i; } - aCurrentPosition->aObjList.erase( aObjIt ); - break; + ++i; } + aCurrentPosition->aObjList.erase( aObjIt ); } } diff --git a/comphelper/source/misc/componentmodule.cxx b/comphelper/source/misc/componentmodule.cxx index 786d6d7885cd..f2645f3c4260 100644 --- a/comphelper/source/misc/componentmodule.cxx +++ b/comphelper/source/misc/componentmodule.cxx @@ -82,17 +82,14 @@ namespace comphelper { Reference< XInterface > xReturn; - for ( ComponentDescriptions::const_iterator component = m_pImpl->m_aRegisteredComponents.begin(); - component != m_pImpl->m_aRegisteredComponents.end(); - ++component - ) + for (const auto& rComponent : m_pImpl->m_aRegisteredComponents) { - if ( component->sImplementationName == _rImplementationName ) + if ( rComponent.sImplementationName == _rImplementationName ) { - xReturn = component->pFactoryCreationFunc( - component->pComponentCreationFunc, - component->sImplementationName, - component->aSupportedServices, + xReturn = rComponent.pFactoryCreationFunc( + rComponent.pComponentCreationFunc, + rComponent.sImplementationName, + rComponent.aSupportedServices, nullptr ); if ( xReturn.is() ) diff --git a/comphelper/source/misc/docpasswordhelper.cxx b/comphelper/source/misc/docpasswordhelper.cxx index 890a25fd92d4..a0d2907c4323 100644 --- a/comphelper/source/misc/docpasswordhelper.cxx +++ b/comphelper/source/misc/docpasswordhelper.cxx @@ -431,14 +431,16 @@ OUString DocPasswordHelper::GetOoxHashAsBase64( *pbIsDefaultPassword = false; if( pDefaultPasswords ) { - for( std::vector< OUString >::const_iterator aIt = pDefaultPasswords->begin(), aEnd = pDefaultPasswords->end(); (eResult == DocPasswordVerifierResult::WrongPassword) && (aIt != aEnd); ++aIt ) + for( const auto& rPassword : *pDefaultPasswords ) { - OSL_ENSURE( !aIt->isEmpty(), "DocPasswordHelper::requestAndVerifyDocPassword - unexpected empty default password" ); - if( !aIt->isEmpty() ) + OSL_ENSURE( !rPassword.isEmpty(), "DocPasswordHelper::requestAndVerifyDocPassword - unexpected empty default password" ); + if( !rPassword.isEmpty() ) { - eResult = rVerifier.verifyPassword( *aIt, aEncData ); + eResult = rVerifier.verifyPassword( rPassword, aEncData ); if( pbIsDefaultPassword ) *pbIsDefaultPassword = eResult == DocPasswordVerifierResult::OK; + if( eResult != DocPasswordVerifierResult::WrongPassword ) + break; } } } diff --git a/comphelper/source/misc/numberedcollection.cxx b/comphelper/source/misc/numberedcollection.cxx index 671804386ea6..43aa31f972ec 100644 --- a/comphelper/source/misc/numberedcollection.cxx +++ b/comphelper/source/misc/numberedcollection.cxx @@ -198,18 +198,14 @@ OUString SAL_CALL NumberedCollection::getUntitledPrefix() ::osl::ResettableMutexGuard aLock(m_aMutex); { TDeadItemList lDeadItems; - TNumberedItemHash::const_iterator pComponent; - for ( pComponent = m_lComponents.begin (); - pComponent != m_lComponents.end (); - ++pComponent ) + for (const auto& [rComponent, rItem] : m_lComponents) { - const TNumberedItem& rItem = pComponent->second; const css::uno::Reference< css::uno::XInterface > xItem = rItem.xItem.get(); if ( ! xItem.is ()) { - lDeadItems.push_back(pComponent->first); + lDeadItems.push_back(rComponent); continue; } @@ -233,13 +229,8 @@ OUString SAL_CALL NumberedCollection::getUntitledPrefix() void NumberedCollection::impl_cleanUpDeadItems ( TNumberedItemHash& lItems , const TDeadItemList& lDeadItems) { - TDeadItemList::const_iterator pIt; - - for ( pIt = lDeadItems.begin (); - pIt != lDeadItems.end (); - ++pIt ) + for (const long& rDeadItem : lDeadItems) { - const long& rDeadItem = *pIt; lItems.erase(rDeadItem); } } diff --git a/comphelper/source/misc/storagehelper.cxx b/comphelper/source/misc/storagehelper.cxx index 4a41d8b8de05..33ae9875da8b 100644 --- a/comphelper/source/misc/storagehelper.cxx +++ b/comphelper/source/misc/storagehelper.cxx @@ -632,16 +632,14 @@ LifecycleProxy::~LifecycleProxy() { } void LifecycleProxy::commitStorages() { - for (Impl::reverse_iterator iter = m_xBadness->rbegin(); - iter != m_xBadness->rend(); ++iter) // reverse order (outwards) - { - uno::Reference<embed::XTransactedObject> const xTransaction(*iter, - uno::UNO_QUERY); - if (xTransaction.is()) - { - xTransaction->commit(); - } - } + std::for_each(m_xBadness->rbegin(), m_xBadness->rend(), // reverse order (outwards) + [](Impl::reference rxItem) { + uno::Reference<embed::XTransactedObject> const xTransaction(rxItem, uno::UNO_QUERY); + if (xTransaction.is()) + { + xTransaction->commit(); + } + }); } static void splitPath( std::vector<OUString> &rElems, diff --git a/comphelper/source/property/propertycontainerhelper.cxx b/comphelper/source/property/propertycontainerhelper.cxx index 11e3640f9485..efe2b0672102 100644 --- a/comphelper/source/property/propertycontainerhelper.cxx +++ b/comphelper/source/property/propertycontainerhelper.cxx @@ -178,13 +178,10 @@ namespace void OPropertyContainerHelper::implPushBackProperty(const PropertyDescription& _rProp) { #ifdef DBG_UTIL - for ( PropertiesIterator checkConflicts = m_aProperties.begin(); - checkConflicts != m_aProperties.end(); - ++checkConflicts - ) + for (auto& checkConflicts : m_aProperties) { - OSL_ENSURE(checkConflicts->aProperty.Name != _rProp.aProperty.Name, "OPropertyContainerHelper::implPushBackProperty: name already exists!"); - OSL_ENSURE(checkConflicts->aProperty.Handle != _rProp.aProperty.Handle, "OPropertyContainerHelper::implPushBackProperty: handle already exists!"); + OSL_ENSURE(checkConflicts.aProperty.Name != _rProp.aProperty.Name, "OPropertyContainerHelper::implPushBackProperty: name already exists!"); + OSL_ENSURE(checkConflicts.aProperty.Handle != _rProp.aProperty.Handle, "OPropertyContainerHelper::implPushBackProperty: handle already exists!"); } #endif @@ -464,15 +461,13 @@ void OPropertyContainerHelper::describeProperties(Sequence< Property >& _rProps) Sequence< Property > aOwnProps(m_aProperties.size()); Property* pOwnProps = aOwnProps.getArray(); - for ( ConstPropertiesIterator aLoop = m_aProperties.begin(); - aLoop != m_aProperties.end(); - ++aLoop, ++pOwnProps - ) + for (const auto& rProp : m_aProperties) { - pOwnProps->Name = aLoop->aProperty.Name; - pOwnProps->Handle = aLoop->aProperty.Handle; - pOwnProps->Attributes = static_cast<sal_Int16>(aLoop->aProperty.Attributes); - pOwnProps->Type = aLoop->aProperty.Type; + pOwnProps->Name = rProp.aProperty.Name; + pOwnProps->Handle = rProp.aProperty.Handle; + pOwnProps->Attributes = static_cast<sal_Int16>(rProp.aProperty.Attributes); + pOwnProps->Type = rProp.aProperty.Type; + ++pOwnProps; } // as our property vector is sorted by handles, not by name, we have to sort aOwnProps |