loplugin:flatten in ucbhelper

Change-Id: Ic5a8ce908671bd492395bff01aa211b8bdd74ca7
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/100008
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
This commit is contained in:
Noel Grandin
2020-08-03 15:56:20 +02:00
parent 186c34af5d
commit c82dae439e
7 changed files with 339 additions and 339 deletions

View File

@@ -1314,21 +1314,21 @@ css::uno::Any SAL_CALL ContentEventListener_Impl::queryInterface( const css::uno
// virtual // virtual
void SAL_CALL ContentEventListener_Impl::contentEvent( const ContentEvent& evt ) void SAL_CALL ContentEventListener_Impl::contentEvent( const ContentEvent& evt )
{ {
if ( evt.Source == m_rContent.m_xContent ) if ( evt.Source != m_rContent.m_xContent )
return;
switch ( evt.Action )
{ {
switch ( evt.Action ) case ContentAction::DELETED:
{ m_rContent.reinit( Reference< XContent >() );
case ContentAction::DELETED: break;
m_rContent.reinit( Reference< XContent >() );
break;
case ContentAction::EXCHANGED: case ContentAction::EXCHANGED:
m_rContent.reinit( evt.Content ); m_rContent.reinit( evt.Content );
break; break;
default: default:
break; break;
}
} }
} }

View File

@@ -819,104 +819,104 @@ void InternetProxyDecider_Impl::setNoProxyList(
m_aNoProxyList.clear(); m_aNoProxyList.clear();
if ( !rNoProxyList.isEmpty() ) if ( rNoProxyList.isEmpty() )
return;
// List of connection endpoints hostname[:port],
// separated by semicolon. Wildcards allowed.
sal_Int32 nPos = 0;
sal_Int32 nEnd = rNoProxyList.indexOf( ';' );
sal_Int32 nLen = rNoProxyList.getLength();
do
{ {
// List of connection endpoints hostname[:port], if ( nEnd == -1 )
// separated by semicolon. Wildcards allowed. nEnd = nLen;
sal_Int32 nPos = 0; OUString aToken = rNoProxyList.copy( nPos, nEnd - nPos );
sal_Int32 nEnd = rNoProxyList.indexOf( ';' );
sal_Int32 nLen = rNoProxyList.getLength();
do if ( !aToken.isEmpty() )
{ {
if ( nEnd == -1 ) OUString aServer;
nEnd = nLen; OUString aPort;
OUString aToken = rNoProxyList.copy( nPos, nEnd - nPos ); // numerical IPv6 address?
bool bIPv6Address = false;
sal_Int32 nClosedBracketPos = aToken.indexOf( ']' );
if ( nClosedBracketPos == -1 )
nClosedBracketPos = 0;
else
bIPv6Address = true;
if ( !aToken.isEmpty() ) sal_Int32 nColonPos = aToken.indexOf( ':', nClosedBracketPos );
if ( nColonPos == -1 )
{ {
OUString aServer; // No port given, server pattern equals current token
OUString aPort; aPort = "*";
if ( aToken.indexOf( '*' ) == -1 )
// numerical IPv6 address?
bool bIPv6Address = false;
sal_Int32 nClosedBracketPos = aToken.indexOf( ']' );
if ( nClosedBracketPos == -1 )
nClosedBracketPos = 0;
else
bIPv6Address = true;
sal_Int32 nColonPos = aToken.indexOf( ':', nClosedBracketPos );
if ( nColonPos == -1 )
{ {
// No port given, server pattern equals current token // pattern describes exactly one server
aPort = "*"; aServer = aToken;
if ( aToken.indexOf( '*' ) == -1 )
{
// pattern describes exactly one server
aServer = aToken;
}
aToken += ":*";
}
else
{
// Port given, extract server pattern
sal_Int32 nAsteriskPos = aToken.indexOf( '*' );
aPort = aToken.copy( nColonPos + 1 );
if ( nAsteriskPos < nColonPos )
{
// pattern describes exactly one server
aServer = aToken.copy( 0, nColonPos );
}
} }
OUStringBuffer aFullyQualifiedHost; aToken += ":*";
if ( !aServer.isEmpty() ) }
else
{
// Port given, extract server pattern
sal_Int32 nAsteriskPos = aToken.indexOf( '*' );
aPort = aToken.copy( nColonPos + 1 );
if ( nAsteriskPos < nColonPos )
{ {
// Remember fully qualified server name if current list // pattern describes exactly one server
// entry specifies exactly one non-fully qualified server aServer = aToken.copy( 0, nColonPos );
// name. }
}
// remove square brackets from host name in case it's OUStringBuffer aFullyQualifiedHost;
// a numerical IPv6 address. if ( !aServer.isEmpty() )
{
// Remember fully qualified server name if current list
// entry specifies exactly one non-fully qualified server
// name.
// remove square brackets from host name in case it's
// a numerical IPv6 address.
if ( bIPv6Address )
aServer = aServer.copy( 1, aServer.getLength() - 2 );
// This might be quite expensive (DNS lookup).
const osl::SocketAddr aAddr( aServer, 0 );
OUString aTmp = aAddr.getHostname().toAsciiLowerCase();
if ( aTmp != aServer.toAsciiLowerCase() )
{
if ( bIPv6Address ) if ( bIPv6Address )
aServer = aServer.copy( 1, aServer.getLength() - 2 );
// This might be quite expensive (DNS lookup).
const osl::SocketAddr aAddr( aServer, 0 );
OUString aTmp = aAddr.getHostname().toAsciiLowerCase();
if ( aTmp != aServer.toAsciiLowerCase() )
{ {
if ( bIPv6Address ) aFullyQualifiedHost.append( "[" );
{ aFullyQualifiedHost.append( aTmp );
aFullyQualifiedHost.append( "[" ); aFullyQualifiedHost.append( "]" );
aFullyQualifiedHost.append( aTmp );
aFullyQualifiedHost.append( "]" );
}
else
{
aFullyQualifiedHost.append( aTmp );
}
aFullyQualifiedHost.append( ":" );
aFullyQualifiedHost.append( aPort );
} }
else
{
aFullyQualifiedHost.append( aTmp );
}
aFullyQualifiedHost.append( ":" );
aFullyQualifiedHost.append( aPort );
} }
m_aNoProxyList.emplace_back( WildCard( aToken ),
WildCard( aFullyQualifiedHost.makeStringAndClear() ) );
} }
if ( nEnd != nLen ) m_aNoProxyList.emplace_back( WildCard( aToken ),
{ WildCard( aFullyQualifiedHost.makeStringAndClear() ) );
nPos = nEnd + 1; }
nEnd = rNoProxyList.indexOf( ';', nPos );
} if ( nEnd != nLen )
{
nPos = nEnd + 1;
nEnd = rNoProxyList.indexOf( ';', nPos );
} }
while ( nEnd != nLen );
} }
while ( nEnd != nLen );
} }
} // namespace proxydecider_impl } // namespace proxydecider_impl

View File

@@ -402,60 +402,60 @@ void SAL_CALL ContentImplHelper::addProperty(
OSL_ENSURE( xSet.is(), OSL_ENSURE( xSet.is(),
"ContentImplHelper::addProperty - No property set!" ); "ContentImplHelper::addProperty - No property set!" );
if ( xSet.is() ) if ( !xSet.is() )
return;
uno::Reference< beans::XPropertyContainer > xContainer(
xSet, uno::UNO_QUERY );
OSL_ENSURE(
xContainer.is(),
"ContentImplHelper::addProperty - No property container!" );
if ( !xContainer.is() )
return;
// Property is always removable.
Attributes |= beans::PropertyAttribute::REMOVABLE;
try
{ {
uno::Reference< beans::XPropertyContainer > xContainer( xContainer->addProperty( Name, Attributes, DefaultValue );
xSet, uno::UNO_QUERY ); }
catch ( beans::PropertyExistException const & )
{
OSL_FAIL( "ContentImplHelper::addProperty - Exists!" );
throw;
}
catch ( beans::IllegalTypeException const & )
{
OSL_FAIL( "ContentImplHelper::addProperty - Wrong Type!" );
throw;
}
catch ( lang::IllegalArgumentException const & )
{
OSL_FAIL( "ContentImplHelper::addProperty - Illegal Arg!" );
throw;
}
OSL_ENSURE( // Success!
xContainer.is(),
"ContentImplHelper::addProperty - No property container!" );
if ( xContainer.is() ) if ( m_pImpl->m_xPropSetInfo.is() )
{ {
// Property is always removable. // Info cached in propertyset info is invalid now!
Attributes |= beans::PropertyAttribute::REMOVABLE; m_pImpl->m_xPropSetInfo->reset();
}
try // Notify propertyset info change listeners.
{ if ( m_pImpl->m_pPropSetChangeListeners &&
xContainer->addProperty( Name, Attributes, DefaultValue ); m_pImpl->m_pPropSetChangeListeners->getLength() )
} {
catch ( beans::PropertyExistException const & ) beans::PropertySetInfoChangeEvent evt(
{ static_cast< cppu::OWeakObject * >( this ),
OSL_FAIL( "ContentImplHelper::addProperty - Exists!" ); Name,
throw; -1, // No handle available
} beans::PropertySetInfoChange::PROPERTY_INSERTED );
catch ( beans::IllegalTypeException const & ) notifyPropertySetInfoChange( evt );
{
OSL_FAIL( "ContentImplHelper::addProperty - Wrong Type!" );
throw;
}
catch ( lang::IllegalArgumentException const & )
{
OSL_FAIL( "ContentImplHelper::addProperty - Illegal Arg!" );
throw;
}
// Success!
if ( m_pImpl->m_xPropSetInfo.is() )
{
// Info cached in propertyset info is invalid now!
m_pImpl->m_xPropSetInfo->reset();
}
// Notify propertyset info change listeners.
if ( m_pImpl->m_pPropSetChangeListeners &&
m_pImpl->m_pPropSetChangeListeners->getLength() )
{
beans::PropertySetInfoChangeEvent evt(
static_cast< cppu::OWeakObject * >( this ),
Name,
-1, // No handle available
beans::PropertySetInfoChange::PROPERTY_INSERTED );
notifyPropertySetInfoChange( evt );
}
}
} }
} }
@@ -490,69 +490,69 @@ void SAL_CALL ContentImplHelper::removeProperty( const OUString& Name )
// Open persistent property set, if exists. // Open persistent property set, if exists.
uno::Reference< css::ucb::XPersistentPropertySet > xSet( uno::Reference< css::ucb::XPersistentPropertySet > xSet(
getAdditionalPropertySet( false ) ); getAdditionalPropertySet( false ) );
if ( xSet.is() ) if ( !xSet.is() )
return;
uno::Reference< beans::XPropertyContainer > xContainer(
xSet, uno::UNO_QUERY );
OSL_ENSURE(
xContainer.is(),
"ContentImplHelper::removeProperty - No property container!" );
if ( !xContainer.is() )
return;
try
{ {
uno::Reference< beans::XPropertyContainer > xContainer( xContainer->removeProperty( Name );
xSet, uno::UNO_QUERY ); }
catch ( beans::UnknownPropertyException const & )
{
OSL_FAIL( "ContentImplHelper::removeProperty - Unknown!" );
throw;
}
catch ( beans::NotRemoveableException const & )
{
OSL_FAIL(
"ContentImplHelper::removeProperty - Unremovable!" );
throw;
}
OSL_ENSURE( xContainer = nullptr;
xContainer.is(),
"ContentImplHelper::removeProperty - No property container!" );
if ( xContainer.is() ) // Success!
if ( !xSet->getPropertySetInfo()->getProperties().hasElements() )
{
// Remove empty propertyset from registry.
uno::Reference< css::ucb::XPropertySetRegistry >
xReg = xSet->getRegistry();
if ( xReg.is() )
{ {
try OUString aKey( xSet->getKey() );
{ xSet = nullptr;
xContainer->removeProperty( Name ); xReg->removePropertySet( aKey );
}
catch ( beans::UnknownPropertyException const & )
{
OSL_FAIL( "ContentImplHelper::removeProperty - Unknown!" );
throw;
}
catch ( beans::NotRemoveableException const & )
{
OSL_FAIL(
"ContentImplHelper::removeProperty - Unremovable!" );
throw;
}
xContainer = nullptr;
// Success!
if ( !xSet->getPropertySetInfo()->getProperties().hasElements() )
{
// Remove empty propertyset from registry.
uno::Reference< css::ucb::XPropertySetRegistry >
xReg = xSet->getRegistry();
if ( xReg.is() )
{
OUString aKey( xSet->getKey() );
xSet = nullptr;
xReg->removePropertySet( aKey );
}
}
if ( m_pImpl->m_xPropSetInfo.is() )
{
// Info cached in propertyset info is invalid now!
m_pImpl->m_xPropSetInfo->reset();
}
// Notify propertyset info change listeners.
if ( m_pImpl->m_pPropSetChangeListeners &&
m_pImpl->m_pPropSetChangeListeners->getLength() )
{
beans::PropertySetInfoChangeEvent evt(
static_cast< cppu::OWeakObject * >( this ),
Name,
-1, // No handle available
beans::PropertySetInfoChange::PROPERTY_REMOVED );
notifyPropertySetInfoChange( evt );
}
} }
} }
if ( m_pImpl->m_xPropSetInfo.is() )
{
// Info cached in propertyset info is invalid now!
m_pImpl->m_xPropSetInfo->reset();
}
// Notify propertyset info change listeners.
if ( m_pImpl->m_pPropSetChangeListeners &&
m_pImpl->m_pPropSetChangeListeners->getLength() )
{
beans::PropertySetInfoChangeEvent evt(
static_cast< cppu::OWeakObject * >( this ),
Name,
-1, // No handle available
beans::PropertySetInfoChange::PROPERTY_REMOVED );
notifyPropertySetInfoChange( evt );
}
} }
// virtual // virtual
@@ -644,75 +644,75 @@ void ContentImplHelper::notifyPropertiesChange(
return; return;
sal_Int32 nCount = evt.getLength(); sal_Int32 nCount = evt.getLength();
if ( nCount ) if ( !nCount )
return;
// First, notify listeners interested in changes of every property.
cppu::OInterfaceContainerHelper* pAllPropsContainer
= m_pImpl->m_pPropertyChangeListeners->getContainer(
OUString() );
if ( pAllPropsContainer )
{ {
// First, notify listeners interested in changes of every property. cppu::OInterfaceIteratorHelper aIter( *pAllPropsContainer );
cppu::OInterfaceContainerHelper* pAllPropsContainer while ( aIter.hasMoreElements() )
= m_pImpl->m_pPropertyChangeListeners->getContainer(
OUString() );
if ( pAllPropsContainer )
{ {
cppu::OInterfaceIteratorHelper aIter( *pAllPropsContainer ); // Propagate event.
uno::Reference< beans::XPropertiesChangeListener > xListener(
aIter.next(), uno::UNO_QUERY );
if ( xListener.is() )
xListener->propertiesChange( evt );
}
}
PropertiesEventListenerMap aListeners;
for ( const beans::PropertyChangeEvent& rEvent : evt )
{
const OUString& rName = rEvent.PropertyName;
cppu::OInterfaceContainerHelper* pPropsContainer
= m_pImpl->m_pPropertyChangeListeners->getContainer( rName );
if ( pPropsContainer )
{
cppu::OInterfaceIteratorHelper aIter( *pPropsContainer );
while ( aIter.hasMoreElements() ) while ( aIter.hasMoreElements() )
{ {
// Propagate event. PropertyEventSequence* p = nullptr;
uno::Reference< beans::XPropertiesChangeListener > xListener(
aIter.next(), uno::UNO_QUERY );
if ( xListener.is() )
xListener->propertiesChange( evt );
}
}
PropertiesEventListenerMap aListeners; beans::XPropertiesChangeListener* pListener =
static_cast< beans::XPropertiesChangeListener * >(
for ( const beans::PropertyChangeEvent& rEvent : evt ) aIter.next() );
{ PropertiesEventListenerMap::iterator it =
const OUString& rName = rEvent.PropertyName; aListeners.find( pListener );
if ( it == aListeners.end() )
cppu::OInterfaceContainerHelper* pPropsContainer
= m_pImpl->m_pPropertyChangeListeners->getContainer( rName );
if ( pPropsContainer )
{
cppu::OInterfaceIteratorHelper aIter( *pPropsContainer );
while ( aIter.hasMoreElements() )
{ {
PropertyEventSequence* p = nullptr; // Not in map - create and insert new entry.
p = &aListeners.emplace( pListener, PropertyEventSequence(nCount)).first->second;
beans::XPropertiesChangeListener* pListener =
static_cast< beans::XPropertiesChangeListener * >(
aIter.next() );
PropertiesEventListenerMap::iterator it =
aListeners.find( pListener );
if ( it == aListeners.end() )
{
// Not in map - create and insert new entry.
p = &aListeners.emplace( pListener, PropertyEventSequence(nCount)).first->second;
}
else
p = &it->second;
if ( p )
p->append( rEvent );
} }
else
p = &it->second;
if ( p )
p->append( rEvent );
} }
} }
}
// Notify listeners. // Notify listeners.
PropertiesEventListenerMap::iterator it = aListeners.begin(); PropertiesEventListenerMap::iterator it = aListeners.begin();
while ( !aListeners.empty() ) while ( !aListeners.empty() )
{ {
beans::XPropertiesChangeListener* pListener = beans::XPropertiesChangeListener* pListener =
static_cast< beans::XPropertiesChangeListener * >( (*it).first ); static_cast< beans::XPropertiesChangeListener * >( (*it).first );
PropertyEventSequence pSeq = std::move(it->second); PropertyEventSequence pSeq = std::move(it->second);
// Remove current element. // Remove current element.
aListeners.erase( it ); aListeners.erase( it );
// Propagate event. // Propagate event.
pListener->propertiesChange( pSeq.getEvents() ); pListener->propertiesChange( pSeq.getEvents() );
it = aListeners.begin(); it = aListeners.begin();
}
} }
} }

View File

@@ -604,53 +604,53 @@ void PropertyValueSet::appendVoid( const OUString& rPropName )
void PropertyValueSet::appendPropertySet( void PropertyValueSet::appendPropertySet(
const Reference< XPropertySet >& rxSet ) const Reference< XPropertySet >& rxSet )
{ {
if ( rxSet.is() ) if ( !rxSet.is() )
return;
Reference< XPropertySetInfo > xInfo = rxSet->getPropertySetInfo();
if ( !xInfo.is() )
return;
const Sequence< Property > aProps = xInfo->getProperties();
Reference< XPropertyAccess > xPropertyAccess( rxSet, UNO_QUERY );
if ( xPropertyAccess.is() )
{ {
Reference< XPropertySetInfo > xInfo = rxSet->getPropertySetInfo(); // Efficient: Get all prop values with one ( remote) call.
if ( xInfo.is() )
const Sequence< css::beans::PropertyValue > aPropValues
= xPropertyAccess->getPropertyValues();
for ( const css::beans::PropertyValue& rPropValue : aPropValues )
{ {
const Sequence< Property > aProps = xInfo->getProperties(); // Find info for current property value.
auto pProp = std::find_if(aProps.begin(), aProps.end(),
Reference< XPropertyAccess > xPropertyAccess( rxSet, UNO_QUERY ); [&rPropValue](const Property& rProp) { return rProp.Name == rPropValue.Name; });
if ( xPropertyAccess.is() ) if (pProp != aProps.end())
{ {
// Efficient: Get all prop values with one ( remote) call. // Found!
appendObject( *pProp, rPropValue.Value );
const Sequence< css::beans::PropertyValue > aPropValues
= xPropertyAccess->getPropertyValues();
for ( const css::beans::PropertyValue& rPropValue : aPropValues )
{
// Find info for current property value.
auto pProp = std::find_if(aProps.begin(), aProps.end(),
[&rPropValue](const Property& rProp) { return rProp.Name == rPropValue.Name; });
if (pProp != aProps.end())
{
// Found!
appendObject( *pProp, rPropValue.Value );
}
}
} }
else }
}
else
{
// Get every single prop value with one ( remote) call.
for ( const Property& rProp : aProps )
{
try
{ {
// Get every single prop value with one ( remote) call. Any aValue = rxSet->getPropertyValue( rProp.Name );
for ( const Property& rProp : aProps ) if ( aValue.hasValue() )
{ appendObject( rProp, aValue );
try }
{ catch (const UnknownPropertyException&)
Any aValue = rxSet->getPropertyValue( rProp.Name ); {
}
if ( aValue.hasValue() ) catch (const WrappedTargetException&)
appendObject( rProp, aValue ); {
}
catch (const UnknownPropertyException&)
{
}
catch (const WrappedTargetException&)
{
}
}
} }
} }
} }

View File

@@ -181,19 +181,19 @@ void ContentProviderImplHelper::queryExistingContents(
void ContentProviderImplHelper::registerNewContent( void ContentProviderImplHelper::registerNewContent(
const uno::Reference< ucb::XContent > & xContent ) const uno::Reference< ucb::XContent > & xContent )
{ {
if ( xContent.is() ) if ( !xContent.is() )
{ return;
osl::MutexGuard aGuard( m_aMutex );
cleanupRegisteredContents(); osl::MutexGuard aGuard( m_aMutex );
const OUString aURL( cleanupRegisteredContents();
xContent->getIdentifier()->getContentIdentifier() );
ucbhelper_impl::Contents::const_iterator it const OUString aURL(
= m_pImpl->m_aContents.find( aURL ); xContent->getIdentifier()->getContentIdentifier() );
if ( it == m_pImpl->m_aContents.end() ) ucbhelper_impl::Contents::const_iterator it
m_pImpl->m_aContents[ aURL ] = xContent; = m_pImpl->m_aContents.find( aURL );
} if ( it == m_pImpl->m_aContents.end() )
m_pImpl->m_aContents[ aURL ] = xContent;
} }
uno::Reference< css::ucb::XPropertySetRegistry > uno::Reference< css::ucb::XPropertySetRegistry >

View File

@@ -1404,22 +1404,22 @@ PropertySetInfo::PropertySetInfo(
: m_pProps( new uno::Sequence< beans::Property >( nProps ) ) : m_pProps( new uno::Sequence< beans::Property >( nProps ) )
{ {
if ( nProps ) if ( !nProps )
return;
const PropertyInfo* pEntry = pProps;
beans::Property* pProperties = m_pProps->getArray();
for ( sal_Int32 n = 0; n < nProps; ++n )
{ {
const PropertyInfo* pEntry = pProps; beans::Property& rProp = pProperties[ n ];
beans::Property* pProperties = m_pProps->getArray();
for ( sal_Int32 n = 0; n < nProps; ++n ) rProp.Name = OUString::createFromAscii( pEntry->pName );
{ rProp.Handle = pEntry->nHandle;
beans::Property& rProp = pProperties[ n ]; rProp.Type = pEntry->pGetCppuType();
rProp.Attributes = pEntry->nAttributes;
rProp.Name = OUString::createFromAscii( pEntry->pName ); pEntry++;
rProp.Handle = pEntry->nHandle;
rProp.Type = pEntry->pGetCppuType();
rProp.Attributes = pEntry->nAttributes;
pEntry++;
}
} }
} }

View File

@@ -231,30 +231,30 @@ void ResultSetImplHelper::init( bool bStatic )
{ {
osl::MutexGuard aGuard( m_aMutex ); osl::MutexGuard aGuard( m_aMutex );
if ( !m_bInitDone ) if ( m_bInitDone )
return;
if ( bStatic )
{ {
if ( bStatic ) // virtual... derived class fills m_xResultSet1
{ initStatic();
// virtual... derived class fills m_xResultSet1
initStatic();
OSL_ENSURE( m_xResultSet1.is(), OSL_ENSURE( m_xResultSet1.is(),
"ResultSetImplHelper::init - No 1st result set!" ); "ResultSetImplHelper::init - No 1st result set!" );
m_bStatic = true; m_bStatic = true;
}
else
{
// virtual... derived class fills m_xResultSet1 and m_xResultSet2
initDynamic();
OSL_ENSURE( m_xResultSet1.is(),
"ResultSetImplHelper::init - No 1st result set!" );
OSL_ENSURE( m_xResultSet2.is(),
"ResultSetImplHelper::init - No 2nd result set!" );
m_bStatic = false;
}
m_bInitDone = true;
} }
else
{
// virtual... derived class fills m_xResultSet1 and m_xResultSet2
initDynamic();
OSL_ENSURE( m_xResultSet1.is(),
"ResultSetImplHelper::init - No 1st result set!" );
OSL_ENSURE( m_xResultSet2.is(),
"ResultSetImplHelper::init - No 2nd result set!" );
m_bStatic = false;
}
m_bInitDone = true;
} }
} // namespace ucbhelper } // namespace ucbhelper