[Libreoffice-commits] core.git: ucbhelper/source
Arkadiy Illarionov (via logerrit)
logerrit at kemper.freedesktop.org
Fri Jun 28 15:38:41 UTC 2019
ucbhelper/source/client/interceptedinteraction.cxx | 18 +-
ucbhelper/source/client/proxydecider.cxx | 129 +++++++++------------
ucbhelper/source/provider/contenthelper.cxx | 21 ---
ucbhelper/source/provider/contentinfo.cxx | 8 -
ucbhelper/source/provider/propertyvalueset.cxx | 28 +---
ucbhelper/source/provider/providerhelper.cxx | 40 +-----
ucbhelper/source/provider/resultsetmetadata.cxx | 21 ---
7 files changed, 100 insertions(+), 165 deletions(-)
New commits:
commit e1c62463433824c3bdfb3245a19366881544afb9
Author: Arkadiy Illarionov <qarkai at gmail.com>
AuthorDate: Fri Jun 28 01:35:35 2019 +0300
Commit: Arkadiy Illarionov <qarkai at gmail.com>
CommitDate: Fri Jun 28 17:37:54 2019 +0200
Simplify Sequence iterations in ucbhelper
Use range-based loops or replace with STL functions
Change-Id: I4e9f5ae006ecbc7513db7574e0f8e08c6940cdb7
Reviewed-on: https://gerrit.libreoffice.org/74828
Tested-by: Jenkins
Reviewed-by: Arkadiy Illarionov <qarkai at gmail.com>
diff --git a/ucbhelper/source/client/interceptedinteraction.cxx b/ucbhelper/source/client/interceptedinteraction.cxx
index afc2f3bf9576..682732958aee 100644
--- a/ucbhelper/source/client/interceptedinteraction.cxx
+++ b/ucbhelper/source/client/interceptedinteraction.cxx
@@ -48,17 +48,13 @@ InterceptedInteraction::EInterceptionState InterceptedInteraction::intercepted(
css::uno::Reference< css::task::XInteractionContinuation > InterceptedInteraction::extractContinuation(const css::uno::Sequence< css::uno::Reference< css::task::XInteractionContinuation > >& lContinuations,
const css::uno::Type& aType )
{
- const css::uno::Reference< css::task::XInteractionContinuation >* pContinuations = lContinuations.getConstArray();
-
- sal_Int32 c = lContinuations.getLength();
- sal_Int32 i = 0;
-
- for (i=0; i<c; ++i)
- {
- css::uno::Reference< css::uno::XInterface > xCheck(pContinuations[i], css::uno::UNO_QUERY);
- if (xCheck->queryInterface(aType).hasValue())
- return pContinuations[i];
- }
+ const css::uno::Reference< css::task::XInteractionContinuation >* pContinuations = std::find_if(lContinuations.begin(), lContinuations.end(),
+ [&aType](const css::uno::Reference< css::task::XInteractionContinuation >& rContinuation) {
+ css::uno::Reference< css::uno::XInterface > xCheck(rContinuation, css::uno::UNO_QUERY);
+ return xCheck->queryInterface(aType).hasValue();
+ });
+ if (pContinuations != lContinuations.end())
+ return *pContinuations;
return css::uno::Reference< css::task::XInteractionContinuation >();
}
diff --git a/ucbhelper/source/client/proxydecider.cxx b/ucbhelper/source/client/proxydecider.cxx
index 0e290006e94a..e80fa5b708f6 100644
--- a/ucbhelper/source/client/proxydecider.cxx
+++ b/ucbhelper/source/client/proxydecider.cxx
@@ -707,92 +707,85 @@ void SAL_CALL InternetProxyDecider_Impl::changesOccurred(
{
osl::Guard< osl::Mutex > aGuard( m_aMutex );
- sal_Int32 nCount = Event.Changes.getLength();
- if ( nCount )
+ for ( const util::ElementChange& rElem : Event.Changes )
{
- const util::ElementChange* pElementChanges
- = Event.Changes.getConstArray();
- for ( sal_Int32 n = 0; n < nCount; ++n )
+ OUString aKey;
+ if ( ( rElem.Accessor >>= aKey ) && !aKey.isEmpty() )
{
- const util::ElementChange& rElem = pElementChanges[ n ];
- OUString aKey;
- if ( ( rElem.Accessor >>= aKey ) && !aKey.isEmpty() )
+ if ( aKey == PROXY_TYPE_KEY )
{
- if ( aKey == PROXY_TYPE_KEY )
+ sal_Int32 tmp;
+ if ( !( rElem.Element >>= tmp ) )
{
- sal_Int32 tmp;
- if ( !( rElem.Element >>= tmp ) )
- {
- OSL_FAIL( "InternetProxyDecider - changesOccurred - "
- "Error getting config item value!" );
- }
- else
- m_nProxyType = static_cast<ProxyType>(tmp);
+ OSL_FAIL( "InternetProxyDecider - changesOccurred - "
+ "Error getting config item value!" );
}
- else if ( aKey == NO_PROXY_LIST_KEY )
+ else
+ m_nProxyType = static_cast<ProxyType>(tmp);
+ }
+ else if ( aKey == NO_PROXY_LIST_KEY )
+ {
+ OUString aNoProxyList;
+ if ( !( rElem.Element >>= aNoProxyList ) )
{
- OUString aNoProxyList;
- if ( !( rElem.Element >>= aNoProxyList ) )
- {
- OSL_FAIL( "InternetProxyDecider - changesOccurred - "
- "Error getting config item value!" );
- }
-
- setNoProxyList( aNoProxyList );
+ OSL_FAIL( "InternetProxyDecider - changesOccurred - "
+ "Error getting config item value!" );
}
- else if ( aKey == HTTP_PROXY_NAME_KEY )
+
+ setNoProxyList( aNoProxyList );
+ }
+ else if ( aKey == HTTP_PROXY_NAME_KEY )
+ {
+ if ( !( rElem.Element >>= m_aHttpProxy.aName ) )
{
- if ( !( rElem.Element >>= m_aHttpProxy.aName ) )
- {
- OSL_FAIL( "InternetProxyDecider - changesOccurred - "
- "Error getting config item value!" );
- }
+ OSL_FAIL( "InternetProxyDecider - changesOccurred - "
+ "Error getting config item value!" );
}
- else if ( aKey == HTTP_PROXY_PORT_KEY )
+ }
+ else if ( aKey == HTTP_PROXY_PORT_KEY )
+ {
+ if ( !( rElem.Element >>= m_aHttpProxy.nPort ) )
{
- if ( !( rElem.Element >>= m_aHttpProxy.nPort ) )
- {
- OSL_FAIL( "InternetProxyDecider - changesOccurred - "
- "Error getting config item value!" );
- }
-
- if ( m_aHttpProxy.nPort == -1 )
- m_aHttpProxy.nPort = 80; // standard HTTP port.
+ OSL_FAIL( "InternetProxyDecider - changesOccurred - "
+ "Error getting config item value!" );
}
- else if ( aKey == HTTPS_PROXY_NAME_KEY )
+
+ if ( m_aHttpProxy.nPort == -1 )
+ m_aHttpProxy.nPort = 80; // standard HTTP port.
+ }
+ else if ( aKey == HTTPS_PROXY_NAME_KEY )
+ {
+ if ( !( rElem.Element >>= m_aHttpsProxy.aName ) )
{
- if ( !( rElem.Element >>= m_aHttpsProxy.aName ) )
- {
- OSL_FAIL( "InternetProxyDecider - changesOccurred - "
- "Error getting config item value!" );
- }
+ OSL_FAIL( "InternetProxyDecider - changesOccurred - "
+ "Error getting config item value!" );
}
- else if ( aKey == HTTPS_PROXY_PORT_KEY )
+ }
+ else if ( aKey == HTTPS_PROXY_PORT_KEY )
+ {
+ if ( !( rElem.Element >>= m_aHttpsProxy.nPort ) )
{
- if ( !( rElem.Element >>= m_aHttpsProxy.nPort ) )
- {
- OSL_FAIL( "InternetProxyDecider - changesOccurred - "
- "Error getting config item value!" );
- }
-
- if ( m_aHttpsProxy.nPort == -1 )
- m_aHttpsProxy.nPort = 443; // standard HTTPS port.
+ OSL_FAIL( "InternetProxyDecider - changesOccurred - "
+ "Error getting config item value!" );
}
- else if ( aKey == FTP_PROXY_NAME_KEY )
+
+ if ( m_aHttpsProxy.nPort == -1 )
+ m_aHttpsProxy.nPort = 443; // standard HTTPS port.
+ }
+ else if ( aKey == FTP_PROXY_NAME_KEY )
+ {
+ if ( !( rElem.Element >>= m_aFtpProxy.aName ) )
{
- if ( !( rElem.Element >>= m_aFtpProxy.aName ) )
- {
- OSL_FAIL( "InternetProxyDecider - changesOccurred - "
- "Error getting config item value!" );
- }
+ OSL_FAIL( "InternetProxyDecider - changesOccurred - "
+ "Error getting config item value!" );
}
- else if ( aKey == FTP_PROXY_PORT_KEY )
+ }
+ else if ( aKey == FTP_PROXY_PORT_KEY )
+ {
+ if ( !( rElem.Element >>= m_aFtpProxy.nPort ) )
{
- if ( !( rElem.Element >>= m_aFtpProxy.nPort ) )
- {
- OSL_FAIL( "InternetProxyDecider - changesOccurred - "
- "Error getting config item value!" );
- }
+ OSL_FAIL( "InternetProxyDecider - changesOccurred - "
+ "Error getting config item value!" );
}
}
}
diff --git a/ucbhelper/source/provider/contenthelper.cxx b/ucbhelper/source/provider/contenthelper.cxx
index 73b8a67d5949..a7f39fced3d8 100644
--- a/ucbhelper/source/provider/contenthelper.cxx
+++ b/ucbhelper/source/provider/contenthelper.cxx
@@ -303,8 +303,7 @@ void SAL_CALL ContentImplHelper::addPropertiesChangeListener(
m_pImpl->m_pPropertyChangeListeners.reset(
new PropertyChangeListeners( m_aMutex ));
- sal_Int32 nCount = PropertyNames.getLength();
- if ( !nCount )
+ if ( !PropertyNames.hasElements() )
{
// Note: An empty sequence means a listener for "all" properties.
m_pImpl->m_pPropertyChangeListeners->addInterface(
@@ -312,11 +311,8 @@ void SAL_CALL ContentImplHelper::addPropertiesChangeListener(
}
else
{
- const OUString* pSeq = PropertyNames.getConstArray();
-
- for ( sal_Int32 n = 0; n < nCount; ++n )
+ for ( const OUString& rName : PropertyNames )
{
- const OUString& rName = pSeq[ n ];
if ( !rName.isEmpty() )
m_pImpl->m_pPropertyChangeListeners->addInterface(
rName, Listener );
@@ -334,8 +330,7 @@ void SAL_CALL ContentImplHelper::removePropertiesChangeListener(
if ( !m_pImpl->m_pPropertyChangeListeners )
return;
- sal_Int32 nCount = PropertyNames.getLength();
- if ( !nCount )
+ if ( !PropertyNames.hasElements() )
{
// Note: An empty sequence means a listener for "all" properties.
m_pImpl->m_pPropertyChangeListeners->removeInterface(
@@ -343,11 +338,8 @@ void SAL_CALL ContentImplHelper::removePropertiesChangeListener(
}
else
{
- const OUString* pSeq = PropertyNames.getConstArray();
-
- for ( sal_Int32 n = 0; n < nCount; ++n )
+ for ( const OUString& rName : PropertyNames )
{
- const OUString& rName = pSeq[ n ];
if ( !rName.isEmpty() )
m_pImpl->m_pPropertyChangeListeners->removeInterface(
rName, Listener );
@@ -671,11 +663,8 @@ void ContentImplHelper::notifyPropertiesChange(
PropertiesEventListenerMap aListeners;
- const beans::PropertyChangeEvent* pEvents = evt.getConstArray();
-
- for ( sal_Int32 n = 0; n < nCount; ++n )
+ for ( const beans::PropertyChangeEvent& rEvent : evt )
{
- const beans::PropertyChangeEvent& rEvent = pEvents[ n ];
const OUString& rName = rEvent.PropertyName;
cppu::OInterfaceContainerHelper* pPropsContainer
diff --git a/ucbhelper/source/provider/contentinfo.cxx b/ucbhelper/source/provider/contentinfo.cxx
index 6dd522be6955..f5034c2fb2cd 100644
--- a/ucbhelper/source/provider/contentinfo.cxx
+++ b/ucbhelper/source/provider/contentinfo.cxx
@@ -137,12 +137,8 @@ uno::Sequence< beans::Property > SAL_CALL PropertySetInfo::getProperties()
sal_Int32 nPos = m_pProps->getLength();
m_pProps->realloc( nPos + nAddProps );
- beans::Property* pProps = m_pProps->getArray();
- const beans::Property* pAddProps
- = rAddProps.getConstArray();
-
- for ( sal_Int32 n = 0; n < nAddProps; ++n, ++nPos )
- pProps[ nPos ] = pAddProps[ n ];
+ std::copy(rAddProps.begin(), rAddProps.end(),
+ std::next(m_pProps->begin(), nPos));
}
}
}
diff --git a/ucbhelper/source/provider/propertyvalueset.cxx b/ucbhelper/source/provider/propertyvalueset.cxx
index b420de754008..d1adaad4e6f2 100644
--- a/ucbhelper/source/provider/propertyvalueset.cxx
+++ b/ucbhelper/source/provider/propertyvalueset.cxx
@@ -644,8 +644,6 @@ void PropertyValueSet::appendPropertySet(
if ( xInfo.is() )
{
Sequence< Property > aProps = xInfo->getProperties();
- const Property* pProps = aProps.getConstArray();
- sal_Int32 nPropsCount = aProps.getLength();
Reference< XPropertyAccess > xPropertyAccess( rxSet, UNO_QUERY );
if ( xPropertyAccess.is() )
@@ -655,25 +653,15 @@ void PropertyValueSet::appendPropertySet(
Sequence< css::beans::PropertyValue > aPropValues
= xPropertyAccess->getPropertyValues();
- const css::beans::PropertyValue* pPropValues
- = aPropValues.getConstArray();
-
- sal_Int32 nValuesCount = aPropValues.getLength();
- for ( sal_Int32 n = 0; n < nValuesCount; ++n )
+ for ( const css::beans::PropertyValue& rPropValue : aPropValues )
{
- const css::beans::PropertyValue& rPropValue
- = pPropValues[ n ];
-
// Find info for current property value.
- for ( sal_Int32 m = 0; m < nPropsCount; ++m )
+ auto pProp = std::find_if(aProps.begin(), aProps.end(),
+ [&rPropValue](const Property& rProp) { return rProp.Name == rPropValue.Name; });
+ if (pProp != aProps.end())
{
- const Property& rProp = pProps[ m ];
- if ( rProp.Name == rPropValue.Name )
- {
- // Found!
- appendObject( rProp, rPropValue.Value );
- break;
- }
+ // Found!
+ appendObject( *pProp, rPropValue.Value );
}
}
}
@@ -681,10 +669,8 @@ void PropertyValueSet::appendPropertySet(
{
// Get every single prop value with one ( remote) call.
- for ( sal_Int32 n = 0; n < nPropsCount; ++n )
+ for ( const Property& rProp : aProps )
{
- const Property& rProp = pProps[ n ];
-
try
{
Any aValue = rxSet->getPropertyValue( rProp.Name );
diff --git a/ucbhelper/source/provider/providerhelper.cxx b/ucbhelper/source/provider/providerhelper.cxx
index 546410bda68e..e4b6d4dab704 100644
--- a/ucbhelper/source/provider/providerhelper.cxx
+++ b/ucbhelper/source/provider/providerhelper.cxx
@@ -288,8 +288,7 @@ bool ContentProviderImplHelper::renameAdditionalPropertySet(
{
uno::Sequence< OUString > aKeys
= xNameAccess->getElementNames();
- sal_Int32 nCount = aKeys.getLength();
- if ( nCount > 0 )
+ if ( aKeys.hasElements() )
{
OUString aOldKeyWithSlash = rOldKey;
OUString aOldKeyWithoutSlash;
@@ -302,10 +301,8 @@ bool ContentProviderImplHelper::renameAdditionalPropertySet(
aOldKeyWithoutSlash
= rOldKey.copy( 0, rOldKey.getLength() - 1 );
- const OUString* pKeys = aKeys.getConstArray();
- for ( sal_Int32 n = 0; n < nCount; ++n )
+ for ( const OUString& rKey : aKeys )
{
- const OUString& rKey = pKeys[ n ];
if ( rKey.startsWith( aOldKeyWithSlash )
|| rKey == aOldKeyWithoutSlash )
{
@@ -370,8 +367,7 @@ bool ContentProviderImplHelper::copyAdditionalPropertySet(
{
uno::Sequence< OUString > aKeys
= xNameAccess->getElementNames();
- sal_Int32 nCount = aKeys.getLength();
- if ( nCount > 0 )
+ if ( aKeys.hasElements() )
{
OUString aSrcKeyWithSlash = rSourceKey;
OUString aSrcKeyWithoutSlash;
@@ -384,10 +380,8 @@ bool ContentProviderImplHelper::copyAdditionalPropertySet(
aSrcKeyWithoutSlash = rSourceKey.copy(
0, rSourceKey.getLength() - 1 );
- const OUString* pKeys = aKeys.getConstArray();
- for ( sal_Int32 n = 0; n < nCount; ++n )
+ for ( const OUString& rKey : aKeys )
{
- const OUString& rKey = pKeys[ n ];
if ( rKey.startsWith(aSrcKeyWithSlash )
|| rKey == aSrcKeyWithoutSlash )
{
@@ -428,12 +422,11 @@ bool ContentProviderImplHelper::copyAdditionalPropertySet(
// Obtain all values from old set.
uno::Sequence< beans::PropertyValue > aValues
= xOldPropAccess->getPropertyValues();
- sal_Int32 nCount = aValues.getLength();
uno::Sequence< beans::Property > aProps
= xPropSetInfo->getProperties();
- if ( nCount )
+ if ( aValues.hasElements() )
{
// Fail, if property set with new key already exists.
uno::Reference< css::ucb::XPersistentPropertySet >
@@ -452,19 +445,13 @@ bool ContentProviderImplHelper::copyAdditionalPropertySet(
if ( !xNewPropContainer.is() )
return false;
- for ( sal_Int32 n = 0; n < nCount; ++n )
+ for ( const beans::PropertyValue& rValue : aValues )
{
- const beans::PropertyValue& rValue = aValues[ n ];
-
sal_Int16 nAttribs = 0;
- for ( sal_Int32 m = 0; m < aProps.getLength(); ++m )
- {
- if ( aProps[ m ].Name == rValue.Name )
- {
- nAttribs = aProps[ m ].Attributes;
- break;
- }
- }
+ auto pProp = std::find_if(aProps.begin(), aProps.end(),
+ [&rValue](const beans::Property& rProp) { return rProp.Name == rValue.Name; });
+ if (pProp != aProps.end())
+ nAttribs = pProp->Attributes;
try
{
@@ -504,8 +491,7 @@ bool ContentProviderImplHelper::removeAdditionalPropertySet(
{
uno::Sequence< OUString > aKeys
= xNameAccess->getElementNames();
- sal_Int32 nCount = aKeys.getLength();
- if ( nCount > 0 )
+ if ( aKeys.hasElements() )
{
OUString aKeyWithSlash = rKey;
OUString aKeyWithoutSlash;
@@ -518,10 +504,8 @@ bool ContentProviderImplHelper::removeAdditionalPropertySet(
aKeyWithoutSlash
= rKey.copy( 0, rKey.getLength() - 1 );
- const OUString* pKeys = aKeys.getConstArray();
- for ( sal_Int32 n = 0; n < nCount; ++n )
+ for ( const OUString& rCurrKey : aKeys )
{
- const OUString& rCurrKey = pKeys[ n ];
if ( rCurrKey.startsWith(aKeyWithSlash )
|| rCurrKey == aKeyWithoutSlash )
{
diff --git a/ucbhelper/source/provider/resultsetmetadata.cxx b/ucbhelper/source/provider/resultsetmetadata.cxx
index 1fa276f46af1..e8a8155b7365 100644
--- a/ucbhelper/source/provider/resultsetmetadata.cxx
+++ b/ucbhelper/source/provider/resultsetmetadata.cxx
@@ -316,24 +316,15 @@ sal_Int32 SAL_CALL ResultSetMetaData::getColumnType( sal_Int32 column )
// Less (remote) calls...
Sequence< Property > aProps = xInfo->getProperties();
- const Property* pProps1 = aProps.getConstArray();
- sal_Int32 nCount1 = aProps.getLength();
- sal_Int32 nCount = m_aProps.getLength();
- Property* pProps = m_aProps.getArray();
- for ( sal_Int32 n = 0; n < nCount; ++n )
+ for ( Property& rProp : m_aProps )
{
- Property& rProp = pProps[ n ];
-
- for ( sal_Int32 m = 0; m < nCount1; ++m )
+ auto pProp = std::find_if(aProps.begin(), aProps.end(),
+ [&rProp](const Property& rProp1) { return rProp.Name == rProp1.Name; });
+ if (pProp != aProps.end())
{
- const Property& rProp1 = pProps1[ m ];
- if ( rProp.Name == rProp1.Name )
- {
- // Found...
- rProp.Type = rProp1.Type;
- break;
- }
+ // Found...
+ rProp.Type = pProp->Type;
}
}
}
More information about the Libreoffice-commits
mailing list