From 826e7e79f36de0248782213e0196baebc1653e85 Mon Sep 17 00:00:00 2001 From: Mike Kaganski Date: Sun, 28 Apr 2024 00:52:10 +0500 Subject: [PATCH] Simplify a bit Change-Id: I1db779648b273d0c732683042c74bd29666f1b10 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/166785 Reviewed-by: Mike Kaganski Tested-by: Jenkins --- .../source/container/embeddedobjectcontainer.cxx | 39 +++++++---------- comphelper/source/container/enumerablemap.cxx | 8 ++-- comphelper/source/container/enumhelper.cxx | 2 +- .../source/eventattachermgr/eventattachermgr.cxx | 3 +- comphelper/source/misc/docpasswordhelper.cxx | 9 ++-- comphelper/source/misc/sequenceashashmap.cxx | 18 +++----- comphelper/source/misc/xmlsechelper.cxx | 8 +--- .../source/property/ChainablePropertySet.cxx | 36 +++++++--------- comphelper/source/property/MasterPropertySet.cxx | 32 +++++++------- comphelper/source/property/genericpropertyset.cxx | 14 ++----- comphelper/source/property/opropertybag.cxx | 31 ++++++-------- comphelper/source/property/propagg.cxx | 30 +++++-------- comphelper/source/property/propertysethelper.cxx | 49 +++++++--------------- .../source/property/propertystatecontainer.cxx | 44 +++++++------------ comphelper/source/property/propshlp.cxx | 3 +- comphelper/source/property/propstate.cxx | 19 ++++----- 16 files changed, 128 insertions(+), 217 deletions(-) diff --git a/comphelper/source/container/embeddedobjectcontainer.cxx b/comphelper/source/container/embeddedobjectcontainer.cxx index a66ac2dec527..56b50c964823 100644 --- a/comphelper/source/container/embeddedobjectcontainer.cxx +++ b/comphelper/source/container/embeddedobjectcontainer.cxx @@ -1165,12 +1165,9 @@ bool EmbeddedObjectContainer::StoreAsChildren(bool _bOasisFormat,bool _bCreateEm try { comphelper::EmbeddedObjectContainer aCnt( _xStorage ); - const uno::Sequence < OUString > aNames = GetObjectNames(); - const OUString* pIter = aNames.getConstArray(); - const OUString* pEnd = pIter + aNames.getLength(); - for(;pIter != pEnd;++pIter) + for (auto& name : GetObjectNames()) { - uno::Reference < embed::XEmbeddedObject > xObj = GetEmbeddedObject( *pIter ); + uno::Reference xObj = GetEmbeddedObject(name); SAL_WARN_IF( !xObj.is(), "comphelper.container", "An empty entry in the embedded objects list!" ); if ( xObj.is() ) { @@ -1209,13 +1206,13 @@ bool EmbeddedObjectContainer::StoreAsChildren(bool _bOasisFormat,bool _bCreateEm { // if it is an embedded object or the optimized inserting fails the normal inserting should be done if ( _bCreateEmbedded - || !aCnt.InsertGraphicStreamDirectly( xStream, *pIter, aMediaType ) ) - aCnt.InsertGraphicStream( xStream, *pIter, aMediaType ); + || !aCnt.InsertGraphicStreamDirectly(xStream, name, aMediaType)) + aCnt.InsertGraphicStream(xStream, name, aMediaType); } else { // it is a linked object exported into SO7 format - InsertStreamIntoPicturesStorage_Impl( _xStorage, xStream, *pIter ); + InsertStreamIntoPicturesStorage_Impl(_xStorage, xStream, name); } } } @@ -1248,7 +1245,7 @@ bool EmbeddedObjectContainer::StoreAsChildren(bool _bOasisFormat,bool _bCreateEm } catch (const embed::WrongStateException&) { - SAL_WARN("comphelper.container", "failed to store '" << *pIter << "'"); + SAL_WARN("comphelper.container", "failed to store '" << name << "'"); } } @@ -1290,14 +1287,11 @@ bool EmbeddedObjectContainer::StoreAsChildren(bool _bOasisFormat,bool _bCreateEm bool EmbeddedObjectContainer::StoreChildren(bool _bOasisFormat,bool _bObjectsOnly) { bool bResult = true; - const uno::Sequence < OUString > aNames = GetObjectNames(); - const OUString* pIter = aNames.getConstArray(); - const OUString* pEnd = pIter + aNames.getLength(); - for(;pIter != pEnd;++pIter) + for (auto& name : GetObjectNames()) { try { - uno::Reference < embed::XEmbeddedObject > xObj = GetEmbeddedObject( *pIter ); + uno::Reference xObj = GetEmbeddedObject(name); SAL_WARN_IF( !xObj.is(), "comphelper.container", "An empty entry in the embedded objects list!" ); if ( xObj.is() ) { @@ -1316,8 +1310,8 @@ bool EmbeddedObjectContainer::StoreChildren(bool _bOasisFormat,bool _bObjectsOnl &aMediaType ); if ( xStream.is() ) { - if ( !InsertGraphicStreamDirectly( xStream, *pIter, aMediaType ) ) - InsertGraphicStream( xStream, *pIter, aMediaType ); + if (!InsertGraphicStreamDirectly(xStream, name, aMediaType)) + InsertGraphicStream(xStream, name, aMediaType); } } @@ -1341,7 +1335,7 @@ bool EmbeddedObjectContainer::StoreChildren(bool _bOasisFormat,bool _bObjectsOnl // '_bObjectsOnly' mean we are storing to alien formats. // 'isStorageElement' mean current object is NOT a MS OLE format. (may also include in future), i120168 if (_bObjectsOnly && (nCurState == embed::EmbedStates::LOADED || nCurState == embed::EmbedStates::RUNNING) - && (pImpl->mxStorage->isStorageElement( *pIter ) )) + && (pImpl->mxStorage->isStorageElement(name))) { uno::Reference< util::XModifiable > xModifiable( xObj->getComponent(), uno::UNO_QUERY ); if ( xModifiable.is() && xModifiable->isModified()) @@ -1378,7 +1372,7 @@ bool EmbeddedObjectContainer::StoreChildren(bool _bOasisFormat,bool _bObjectsOnl OUString aMediaType; uno::Reference < io::XInputStream > xInStream = GetGraphicStream( xObj, &aMediaType ); if ( xInStream.is() ) - InsertStreamIntoPicturesStorage_Impl( pImpl->mxStorage, xInStream, *pIter ); + InsertStreamIntoPicturesStorage_Impl( pImpl->mxStorage, xInStream, name ); } } catch (const uno::Exception&) @@ -1444,12 +1438,9 @@ uno::Reference< io::XInputStream > EmbeddedObjectContainer::GetGraphicReplacemen bool EmbeddedObjectContainer::SetPersistentEntries(const uno::Reference< embed::XStorage >& _xStorage,bool _bClearModifiedFlag) { bool bError = false; - const uno::Sequence < OUString > aNames = GetObjectNames(); - const OUString* pIter = aNames.getConstArray(); - const OUString* pEnd = pIter + aNames.getLength(); - for(;pIter != pEnd;++pIter) + for (auto& name : GetObjectNames()) { - uno::Reference < embed::XEmbeddedObject > xObj = GetEmbeddedObject( *pIter ); + uno::Reference xObj = GetEmbeddedObject(name); SAL_WARN_IF( !xObj.is(), "comphelper.container", "An empty entry in the embedded objects list!" ); if ( xObj.is() ) { @@ -1459,7 +1450,7 @@ bool EmbeddedObjectContainer::SetPersistentEntries(const uno::Reference< embed:: try { xPersist->setPersistentEntry( _xStorage, - *pIter, + name, embed::EntryInitModes::NO_INIT, uno::Sequence< beans::PropertyValue >(), uno::Sequence< beans::PropertyValue >() ); diff --git a/comphelper/source/container/enumerablemap.cxx b/comphelper/source/container/enumerablemap.cxx index ae78223a20fe..031bd86c3aee 100644 --- a/comphelper/source/container/enumerablemap.cxx +++ b/comphelper/source/container/enumerablemap.cxx @@ -372,12 +372,10 @@ namespace comphelper if (!m_aData.m_pValues || !m_aData.m_pValues->empty()) throw RuntimeException(); - const Pair< Any, Any >* mapping = _initialValues.getConstArray(); - const Pair< Any, Any >* mappingEnd = mapping + _initialValues.getLength(); - for ( ; mapping != mappingEnd; ++mapping ) + for (auto& mapping : _initialValues) { - impl_checkValue_throw( mapping->Second ); - (*m_aData.m_pValues)[ mapping->First ] = mapping->Second; + impl_checkValue_throw(mapping.Second); + (*m_aData.m_pValues)[mapping.First] = mapping.Second; } } diff --git a/comphelper/source/container/enumhelper.cxx b/comphelper/source/container/enumhelper.cxx index 66ba15198232..3390fef86444 100644 --- a/comphelper/source/container/enumhelper.cxx +++ b/comphelper/source/container/enumhelper.cxx @@ -142,7 +142,7 @@ sal_Int32 OEnumerationByName::getLength() const const OUString& OEnumerationByName::getElement(sal_Int32 nIndex) const { if (m_aNames.index() == 0) - return std::get>(m_aNames).getConstArray()[nIndex]; + return std::get>(m_aNames)[nIndex]; else return std::get>(m_aNames)[nIndex]; } diff --git a/comphelper/source/eventattachermgr/eventattachermgr.cxx b/comphelper/source/eventattachermgr/eventattachermgr.cxx index 9a6d4af5afe5..af2c7bbc3edb 100644 --- a/comphelper/source/eventattachermgr/eventattachermgr.cxx +++ b/comphelper/source/eventattachermgr/eventattachermgr.cxx @@ -457,10 +457,9 @@ void ImplEventAttacherManager::registerScriptEvents for( const auto& rObj : aList ) detach( l, nIndex, rObj.xTarget ); - const ScriptEventDescriptor* pArray = ScriptEvents.getConstArray(); sal_Int32 nLen = ScriptEvents.getLength(); for( sal_Int32 i = 0 ; i < nLen ; i++ ) - registerScriptEvent( l, nIndex, pArray[ i ] ); + registerScriptEvent(l, nIndex, ScriptEvents[i]); for( const auto& rObj : aList ) attach( l, nIndex, rObj.xTarget, rObj.aHelper ); diff --git a/comphelper/source/misc/docpasswordhelper.cxx b/comphelper/source/misc/docpasswordhelper.cxx index 1f73bd8d7026..76008b508c68 100644 --- a/comphelper/source/misc/docpasswordhelper.cxx +++ b/comphelper/source/misc/docpasswordhelper.cxx @@ -677,19 +677,16 @@ OUString DocPasswordHelper::GetOoxHashAsBase64( throw uno::RuntimeException("The GpgME library failed to initialize for the OpenPGP protocol."); ctx->setArmor(false); - const uno::Sequence < beans::NamedValue > *pSequence = rGpgProperties.getConstArray(); - const sal_Int32 nLength = rGpgProperties.getLength(); - for ( sal_Int32 i = 0; i < nLength ; i++, pSequence++ ) + for (auto& rSequence : rGpgProperties) { - const beans::NamedValue *pValues = pSequence->getConstArray(); - if ( pSequence->getLength() == 3 ) + if (rSequence.getLength() == 3) { // take CipherValue and try to decrypt that - stop after // the first successful decryption // ctx is setup now, let's decrypt the lot! uno::Sequence < sal_Int8 > aVector; - pValues[2].Value >>= aVector; + rSequence[2].Value >>= aVector; GpgME::Data cipher( reinterpret_cast(aVector.getConstArray()), diff --git a/comphelper/source/misc/sequenceashashmap.cxx b/comphelper/source/misc/sequenceashashmap.cxx index db2c99a7a814..647ccb74974d 100644 --- a/comphelper/source/misc/sequenceashashmap.cxx +++ b/comphelper/source/misc/sequenceashashmap.cxx @@ -202,24 +202,18 @@ void SequenceAsHashMap::operator<<(const css::uno::Sequence< css::beans::Propert { clear(); - sal_Int32 c = lSource.getLength(); - const css::beans::PropertyValue* pSource = lSource.getConstArray(); - - m_aMap.reserve(c); - for (sal_Int32 i=0; i& lSource) { clear(); - sal_Int32 c = lSource.getLength(); - const css::beans::NamedValue* pSource = lSource.getConstArray(); - - m_aMap.reserve(c); - for (sal_Int32 i=0; i>(css::uno::Sequence< css::beans::PropertyValue >& lDestination) const diff --git a/comphelper/source/misc/xmlsechelper.cxx b/comphelper/source/misc/xmlsechelper.cxx index a96ff6937374..e69f734b2b8b 100644 --- a/comphelper/source/misc/xmlsechelper.cxx +++ b/comphelper/source/misc/xmlsechelper.cxx @@ -284,18 +284,14 @@ std::vector< std::pair< OUString, OUString> > parseDN(std::u16string_view rRawSt OUString GetHexString( const css::uno::Sequence< sal_Int8 >& _rSeq, const char* _pSep, sal_uInt16 _nLineBreak ) { - const sal_Int8* pSerNumSeq = _rSeq.getConstArray(); - int nCnt = _rSeq.getLength(); OUStringBuffer aStr; const char pHexDigs[ 17 ] = "0123456789ABCDEF"; char pBuffer[ 3 ] = " "; - sal_uInt8 nNum; sal_uInt16 nBreakStart = _nLineBreak? _nLineBreak : 1; sal_uInt16 nBreak = nBreakStart; - for( int i = 0 ; i < nCnt ; ++i ) + for (sal_Int8 n : _rSeq) { - nNum = sal_uInt8( pSerNumSeq[ i ] ); - + sal_uInt8 nNum = static_cast(n); // exchange the buffer[0] and buffer[1], which make it consistent with Mozilla and Windows pBuffer[ 1 ] = pHexDigs[ nNum & 0x0F ]; nNum >>= 4; diff --git a/comphelper/source/property/ChainablePropertySet.cxx b/comphelper/source/property/ChainablePropertySet.cxx index 0805afe72bcf..d2e7122996ed 100644 --- a/comphelper/source/property/ChainablePropertySet.cxx +++ b/comphelper/source/property/ChainablePropertySet.cxx @@ -124,17 +124,13 @@ void SAL_CALL ChainablePropertySet::setPropertyValues(const Sequence< OUString > _preSetValues(); - const Any * pAny = rValues.getConstArray(); - const OUString * pString = rPropertyNames.getConstArray(); - PropertyInfoHash::const_iterator aEnd = mxInfo->maMap.end(), aIter; - - for ( sal_Int32 i = 0; i < nCount; ++i, ++pString, ++pAny ) + for (sal_Int32 i = 0; i < nCount; ++i) { - aIter = mxInfo->maMap.find ( *pString ); - if ( aIter == aEnd ) - throw RuntimeException( *pString, static_cast< XPropertySet* >( this ) ); + auto aIter = mxInfo->maMap.find(rPropertyNames[i]); + if (aIter == mxInfo->maMap.end()) + throw RuntimeException(rPropertyNames[i], static_cast(this)); - _setSingleValue ( *((*aIter).second), *pAny ); + _setSingleValue(*((*aIter).second), rValues[i]); } _postSetValues(); @@ -156,16 +152,13 @@ Sequence< Any > SAL_CALL ChainablePropertySet::getPropertyValues(const Sequence< _preGetValues(); Any * pAny = aValues.getArray(); - const OUString * pString = rPropertyNames.getConstArray(); - PropertyInfoHash::const_iterator aEnd = mxInfo->maMap.end(), aIter; - - for ( sal_Int32 i = 0; i < nCount; ++i, ++pString, ++pAny ) + for (sal_Int32 i = 0; i < nCount; ++i) { - aIter = mxInfo->maMap.find ( *pString ); - if ( aIter == aEnd ) - throw RuntimeException( *pString, static_cast< XPropertySet* >( this ) ); + auto aIter = mxInfo->maMap.find(rPropertyNames[i]); + if (aIter == mxInfo->maMap.end()) + throw RuntimeException(rPropertyNames[i], static_cast(this)); - _getSingleValue ( *((*aIter).second), *pAny ); + _getSingleValue(*((*aIter).second), pAny[i]); } _postGetValues(); @@ -206,14 +199,15 @@ Sequence< PropertyState > SAL_CALL ChainablePropertySet::getPropertyStates( cons if( nCount ) { PropertyState * pState = aStates.getArray(); - const OUString * pString = rPropertyNames.getConstArray(); PropertyInfoHash::const_iterator aEnd = mxInfo->maMap.end(), aIter; - for ( sal_Int32 i = 0; i < nCount; ++i, ++pString, ++pState ) + for (sal_Int32 i = 0; i < nCount; ++i) { - aIter = mxInfo->maMap.find ( *pString ); + aIter = mxInfo->maMap.find(rPropertyNames[i]); if ( aIter == aEnd ) - throw UnknownPropertyException( *pString, static_cast< XPropertySet* >( this ) ); + throw UnknownPropertyException(rPropertyNames[i], static_cast(this)); + + pState[i] = PropertyState_AMBIGUOUS_VALUE; } } return aStates; diff --git a/comphelper/source/property/MasterPropertySet.cxx b/comphelper/source/property/MasterPropertySet.cxx index 922a4c1c69b4..bd5ce83eaa16 100644 --- a/comphelper/source/property/MasterPropertySet.cxx +++ b/comphelper/source/property/MasterPropertySet.cxx @@ -195,8 +195,6 @@ void SAL_CALL MasterPropertySet::setPropertyValues( const Sequence< OUString >& _preSetValues(); - const Any * pAny = aValues.getConstArray(); - const OUString * pString = aPropertyNames.getConstArray(); PropertyDataHash::const_iterator aEnd = mxInfo->maMap.end(), aIter; //!! have a unique_ptr to an array of OGuards in order to have the @@ -206,14 +204,14 @@ void SAL_CALL MasterPropertySet::setPropertyValues( const Sequence< OUString >& //!! the acquired locks properly released. AutoOGuardArray aOGuardArray( nCount ); - for ( sal_Int32 i = 0; i < nCount; ++i, ++pString, ++pAny ) + for (sal_Int32 i = 0; i < nCount; ++i) { - aIter = mxInfo->maMap.find ( *pString ); + aIter = mxInfo->maMap.find(aPropertyNames[i]); if ( aIter == aEnd ) - throw RuntimeException( *pString, static_cast< XPropertySet* >( this ) ); + throw RuntimeException(aPropertyNames[i], static_cast(this)); if ( (*aIter).second->mnMapId == 0 ) // 0 means it's one of ours ! - _setSingleValue( *((*aIter).second->mpInfo), *pAny ); + _setSingleValue(*((*aIter).second->mpInfo), aValues[i]); else { SlaveData * pSlave = maSlaveMap [ (*aIter).second->mnMapId ]; @@ -226,7 +224,7 @@ void SAL_CALL MasterPropertySet::setPropertyValues( const Sequence< OUString >& pSlave->mxSlave->_preSetValues(); pSlave->SetInit ( true ); } - pSlave->mxSlave->_setSingleValue( *((*aIter).second->mpInfo), *pAny ); + pSlave->mxSlave->_setSingleValue(*((*aIter).second->mpInfo), aValues[i]); } } @@ -257,7 +255,6 @@ Sequence< Any > SAL_CALL MasterPropertySet::getPropertyValues( const Sequence< O _preGetValues(); Any * pAny = aValues.getArray(); - const OUString * pString = aPropertyNames.getConstArray(); PropertyDataHash::const_iterator aEnd = mxInfo->maMap.end(), aIter; //!! have a unique_ptr to an array of OGuards in order to have the @@ -267,14 +264,14 @@ Sequence< Any > SAL_CALL MasterPropertySet::getPropertyValues( const Sequence< O //!! the acquired locks properly released. AutoOGuardArray aOGuardArray( nCount ); - for ( sal_Int32 i = 0; i < nCount; ++i, ++pString, ++pAny ) + for (sal_Int32 i = 0; i < nCount; ++i) { - aIter = mxInfo->maMap.find ( *pString ); + aIter = mxInfo->maMap.find(aPropertyNames[i]); if ( aIter == aEnd ) - throw RuntimeException( *pString, static_cast< XPropertySet* >( this ) ); + throw RuntimeException(aPropertyNames[i], static_cast(this)); if ( (*aIter).second->mnMapId == 0 ) // 0 means it's one of ours ! - _getSingleValue( *((*aIter).second->mpInfo), *pAny ); + _getSingleValue(*((*aIter).second->mpInfo), pAny[i]); else { SlaveData * pSlave = maSlaveMap [ (*aIter).second->mnMapId ]; @@ -287,7 +284,7 @@ Sequence< Any > SAL_CALL MasterPropertySet::getPropertyValues( const Sequence< O pSlave->mxSlave->_preGetValues(); pSlave->SetInit ( true ); } - pSlave->mxSlave->_getSingleValue( *((*aIter).second->mpInfo), *pAny ); + pSlave->mxSlave->_getSingleValue(*((*aIter).second->mpInfo), pAny[i]); } } @@ -348,14 +345,13 @@ Sequence< PropertyState > SAL_CALL MasterPropertySet::getPropertyStates( const S if( nCount ) { PropertyState * pState = aStates.getArray(); - const OUString * pString = rPropertyNames.getConstArray(); PropertyDataHash::const_iterator aEnd = mxInfo->maMap.end(), aIter; - for ( sal_Int32 i = 0; i < nCount; ++i, ++pString, ++pState ) + for (sal_Int32 i = 0; i < nCount; ++i) { - aIter = mxInfo->maMap.find ( *pString ); + aIter = mxInfo->maMap.find(rPropertyNames[i]); if ( aIter == aEnd ) - throw UnknownPropertyException( *pString, static_cast< XPropertySet* >( this ) ); + throw UnknownPropertyException(rPropertyNames[i], static_cast(this)); // 0 means it's one of ours ! if ( (*aIter).second->mnMapId != 0 ) @@ -366,6 +362,8 @@ Sequence< PropertyState > SAL_CALL MasterPropertySet::getPropertyStates( const S pSlave->SetInit ( true ); } } + + pState[i] = PropertyState_AMBIGUOUS_VALUE; } for( const auto& rSlave : maSlaveMap ) { diff --git a/comphelper/source/property/genericpropertyset.cxx b/comphelper/source/property/genericpropertyset.cxx index 747023d2be87..a6392ec757db 100644 --- a/comphelper/source/property/genericpropertyset.cxx +++ b/comphelper/source/property/genericpropertyset.cxx @@ -97,12 +97,9 @@ void SAL_CALL GenericPropertySet::addPropertyChangeListener( const OUString& aPr std::unique_lock aGuard(maMutex); if ( aPropertyName.isEmpty() ) { - Sequence< Property> aSeq = xInfo->getProperties(); - const Property* pIter = aSeq.getConstArray(); - const Property* pEnd = pIter + aSeq.getLength(); - for( ; pIter != pEnd ; ++pIter) + for (auto& prop : xInfo->getProperties()) { - m_aListener.addInterface(aGuard, pIter->Name,xListener); + m_aListener.addInterface(aGuard, prop.Name, xListener); } } else if ( xInfo->hasPropertyByName(aPropertyName) ) @@ -120,12 +117,9 @@ void SAL_CALL GenericPropertySet::removePropertyChangeListener( const OUString& std::unique_lock aGuard(maMutex); if ( aPropertyName.isEmpty() ) { - Sequence< Property> aSeq = xInfo->getProperties(); - const Property* pIter = aSeq.getConstArray(); - const Property* pEnd = pIter + aSeq.getLength(); - for( ; pIter != pEnd ; ++pIter) + for (auto& prop : xInfo->getProperties()) { - m_aListener.removeInterface(aGuard, pIter->Name,xListener); + m_aListener.removeInterface(aGuard, prop.Name, xListener); } } else if ( xInfo->hasPropertyByName(aPropertyName) ) diff --git a/comphelper/source/property/opropertybag.cxx b/comphelper/source/property/opropertybag.cxx index 30201b9ff772..3b4a0498dcef 100644 --- a/comphelper/source/property/opropertybag.cxx +++ b/comphelper/source/property/opropertybag.cxx @@ -404,17 +404,14 @@ namespace comphelper ::cppu::IPropertyArrayHelper& rPropInfo = getInfoHelper(); Sequence< PropertyValue > aPropertyValues( aNames.getLength() ); - const OUString* pName = aNames.getConstArray(); - const OUString* pNamesEnd = aNames.getConstArray() + aNames.getLength(); - const Any* pValue = aValues.getArray(); PropertyValue* pPropertyValue = aPropertyValues.getArray(); - for ( ; pName != pNamesEnd; ++pName, ++pValue, ++pPropertyValue ) + for (sal_Int32 i = 0; i < aNames.getLength(); ++i) { - pPropertyValue->Name = *pName; - pPropertyValue->Handle = rPropInfo.getHandleByName( *pName ); - pPropertyValue->Value = *pValue; - pPropertyValue->State = getPropertyStateByHandle( pPropertyValue->Handle ); + pPropertyValue[i].Name = aNames[i]; + pPropertyValue[i].Handle = rPropInfo.getHandleByName(aNames[i]); + pPropertyValue[i].Value = aValues[i]; + pPropertyValue[i].State = getPropertyStateByHandle(pPropertyValue[i].Handle); } return aPropertyValues; @@ -452,16 +449,12 @@ namespace comphelper sal_Int32 nCount = aNames.getLength(); Sequence< sal_Int32 > aHandles( nCount ); - sal_Int32* pHandle = aHandles.getArray(); - const PropertyValue* pProperty = aProperties.getConstArray(); - for ( const OUString* pName = aNames.getConstArray(); - pName != aNames.getConstArray() + aNames.getLength(); - ++pName, ++pHandle, ++pProperty - ) + sal_Int32* pHandles = aHandles.getArray(); + for (sal_Int32 i = 0; i < nCount; ++i) { ::cppu::IPropertyArrayHelper& rPropInfo = getInfoHelper(); - *pHandle = rPropInfo.getHandleByName( *pName ); - if ( *pHandle != -1 ) + pHandles[i] = rPropInfo.getHandleByName(aNames[i]); + if (pHandles[i] != -1) continue; // there's a property requested which we do not know @@ -469,12 +462,12 @@ namespace comphelper { // add the property sal_Int16 const nAttributes = PropertyAttribute::BOUND | PropertyAttribute::REMOVABLE | PropertyAttribute::MAYBEDEFAULT; - addProperty( *pName, nAttributes, pProperty->Value ); + addProperty(aNames[i], nAttributes, aProperties[i].Value); continue; } // no way out - throw UnknownPropertyException( *pName, *this ); + throw UnknownPropertyException(aNames[i], *this); } // a sequence of values @@ -486,7 +479,7 @@ namespace comphelper ExtractPropertyValue() ); - setFastPropertyValues( nCount, aHandles.getArray(), aValues.getConstArray(), nCount ); + setFastPropertyValues(nCount, pHandles, aValues.getConstArray(), nCount); } catch( const PropertyVetoException& ) { throw; } catch( const IllegalArgumentException& ) { throw; } diff --git a/comphelper/source/property/propagg.cxx b/comphelper/source/property/propagg.cxx index 5a0574460cf4..5acf8a1dc2d5 100644 --- a/comphelper/source/property/propagg.cxx +++ b/comphelper/source/property/propagg.cxx @@ -229,15 +229,13 @@ sal_Int32 OPropertyArrayAggregationHelper::fillHandles( sal_Int32* _pHandles, const css::uno::Sequence< OUString >& _rPropNames ) { sal_Int32 nHitCount = 0; - const OUString* pReqProps = _rPropNames.getConstArray(); - sal_Int32 nReqLen = _rPropNames.getLength(); Property aNameProp; - for( sal_Int32 i = 0; i < nReqLen; ++i ) + for (sal_Int32 i = 0; i < _rPropNames.getLength(); ++i) { - aNameProp.Name = pReqProps[i]; + aNameProp.Name = _rPropNames[i]; auto findIter = std::lower_bound(m_aProperties.begin(), m_aProperties.end(), aNameProp, PropertyCompareByName()); - if ( findIter != m_aProperties.end() && findIter->Name == pReqProps[i] ) + if (findIter != m_aProperties.end() && findIter->Name == _rPropNames[i]) { _pHandles[i] = findIter->Handle; nHitCount++; @@ -386,7 +384,7 @@ void SAL_CALL OPropertySetAggregationHelper::propertiesChange(const css::uno::Se if (1 == nLen) { - const css::beans::PropertyChangeEvent& evt = _rEvents.getConstArray()[0]; + const css::beans::PropertyChangeEvent& evt = _rEvents[0]; OSL_ENSURE(!evt.PropertyName.isEmpty(), "OPropertySetAggregationHelper::propertiesChange : invalid event !"); // we had a bug where this assertion would have us saved a whole day :) (72514) sal_Int32 nHandle = rPH.getHandleByName( evt.PropertyName ); @@ -637,9 +635,6 @@ void SAL_CALL OPropertySetAggregationHelper::setPropertyValues( if (_rValues.getLength() != nLen) throw IllegalArgumentException("lengths do not match", static_cast(this), -1); - const css::uno::Any* pValues = _rValues.getConstArray(); - - // dividing the Names and _rValues // aggregate's names Sequence< OUString > AggPropertyNames( nAggCount ); @@ -656,23 +651,20 @@ void SAL_CALL OPropertySetAggregationHelper::setPropertyValues( Sequence< Any > DelValues( nLen - nAggCount ); Any* pDelValues = DelValues.getArray(); - for ( const OUString& rName : _rPropertyNames ) + for (sal_Int32 i = 0; i < nLen; ++i) { - if ( OPropertyArrayAggregationHelper::PropertyOrigin::Aggregate == rPH.classifyProperty( rName ) ) + if ( OPropertyArrayAggregationHelper::PropertyOrigin::Aggregate == rPH.classifyProperty( _rPropertyNames[i] ) ) { - *pAggNames++ = rName; - *pAggValues++ = *pValues++; + *pAggNames++ = _rPropertyNames[i]; + *pAggValues++ = _rValues[i]; } else { - *pDelNames++ = rName; - *pDelValues++ = *pValues++; + *pDelNames++ = _rPropertyNames[i]; + *pDelValues++ = _rValues[i]; } } - // reset, needed below - pDelValues = DelValues.getArray(); - std::unique_ptr pHandles(new sal_Int32[ nLen - nAggCount ]); // get the map table @@ -700,7 +692,7 @@ void SAL_CALL OPropertySetAggregationHelper::setPropertyValues( throw css::beans::PropertyVetoException(); // Will the property change? if( convertFastPropertyValue( pConvertedValues[ nHitCount ], pOldValues[nHitCount], - pHandles[i], pDelValues[i] ) ) + pHandles[i], DelValues[i] ) ) { // only increment if the property really change pHandles[nHitCount] = pHandles[i]; diff --git a/comphelper/source/property/propertysethelper.cxx b/comphelper/source/property/propertysethelper.cxx index 519b0705fadd..5172fbb17b8f 100644 --- a/comphelper/source/property/propertysethelper.cxx +++ b/comphelper/source/property/propertysethelper.cxx @@ -112,28 +112,22 @@ void SAL_CALL PropertySetHelper::setPropertyValues( const Sequence< OUString >& const sal_Int32 nCount = rPropertyNames.getLength(); if( nCount != rValues.getLength() ) - throw IllegalArgumentException("lengths do not match", uno::Reference(), -1); + throw IllegalArgumentException("lengths do not match", static_cast(this), -1); if( !nCount ) return; std::unique_ptr pEntries(new PropertyMapEntry const *[nCount+1]); pEntries[nCount] = nullptr; - const OUString* pNames = rPropertyNames.getConstArray(); - bool bUnknown = false; - sal_Int32 n; - for( n = 0; !bUnknown && ( n < nCount ); n++, pNames++ ) + for (sal_Int32 n = 0; n < nCount; n++) { - pEntries[n] = find( mxInfo, *pNames ); - bUnknown = nullptr == pEntries[n]; + pEntries[n] = find(mxInfo, rPropertyNames[n]); + if (!pEntries[n]) + throw UnknownPropertyException(rPropertyNames[n], static_cast(this)); } - if( !bUnknown ) - _setPropertyValues( pEntries.get(), rValues.getConstArray() ); - - if( bUnknown ) - throw RuntimeException( *pNames, static_cast< XPropertySet* >( this ) ); + _setPropertyValues(pEntries.get(), rValues.getConstArray()); } Sequence< Any > SAL_CALL PropertySetHelper::getPropertyValues(const Sequence< OUString >& rPropertyNames) @@ -144,22 +138,16 @@ Sequence< Any > SAL_CALL PropertySetHelper::getPropertyValues(const Sequence< OU return Sequence< Any >(); std::unique_ptr pEntries(new PropertyMapEntry const *[nCount+1]); - const OUString* pNames = rPropertyNames.getConstArray(); - bool bUnknown = false; - sal_Int32 n; - for( n = 0; !bUnknown && ( n < nCount ); n++, pNames++ ) + for (sal_Int32 n = 0; n < nCount; n++) { - pEntries[n] = find( mxInfo, *pNames ); - bUnknown = nullptr == pEntries[n]; + pEntries[n] = find(mxInfo, rPropertyNames[n]); + if (!pEntries[n]) + throw UnknownPropertyException(rPropertyNames[n], static_cast(this)); } - if( bUnknown ) - throw RuntimeException( *pNames, static_cast< XPropertySet* >( this ) ); - pEntries[nCount] = nullptr; Sequence< Any > aValues(nCount); - aValues.realloc(nCount); _getPropertyValues( pEntries.get(), aValues.getArray() ); return aValues; @@ -205,26 +193,19 @@ Sequence< PropertyState > SAL_CALL PropertySetHelper::getPropertyStates( const S if( nCount ) { - const OUString* pNames = aPropertyName.getConstArray(); - - bool bUnknown = false; - std::unique_ptr pEntries(new PropertyMapEntry const *[nCount+1]); sal_Int32 n; - for( n = 0; !bUnknown && (n < nCount); n++, pNames++ ) + for (n = 0; n < nCount; n++) { - pEntries[n] = find( mxInfo, *pNames ); - bUnknown = nullptr == pEntries[n]; + pEntries[n] = find(mxInfo, aPropertyName[n]); + if (!pEntries[n]) + throw UnknownPropertyException(aPropertyName[n], static_cast(this)); } pEntries[nCount] = nullptr; - if( !bUnknown ) - _getPropertyStates( pEntries.get(), aStates.getArray() ); - - if( bUnknown ) - throw UnknownPropertyException( *pNames, static_cast< XPropertySet* >( this ) ); + _getPropertyStates(pEntries.get(), aStates.getArray()); } return aStates; diff --git a/comphelper/source/property/propertystatecontainer.cxx b/comphelper/source/property/propertystatecontainer.cxx index 5fbe6252d62b..9ab7f534dc02 100644 --- a/comphelper/source/property/propertystatecontainer.cxx +++ b/comphelper/source/property/propertystatecontainer.cxx @@ -89,46 +89,34 @@ namespace comphelper #ifdef DBG_UTIL // precondition: property sequence is sorted (the algorithm below relies on this) - { - const OUString* pNames = _rPropertyNames.getConstArray(); - const OUString* pNamesCompare = pNames + 1; - const OUString* pNamesEnd = _rPropertyNames.getConstArray() + _rPropertyNames.getLength(); - for ( ; pNamesCompare != pNamesEnd; ++pNames, ++pNamesCompare ) - OSL_PRECOND( pNames->compareTo( *pNamesCompare ) < 0, + OSL_PRECOND(std::is_sorted(_rPropertyNames.begin(), _rPropertyNames.end(), + [](auto& lhs, auto& rhs) { return lhs.compareTo(rhs) < 0; }), "OPropertyStateContainer::getPropertyStates: property sequence not sorted!" ); - } #endif - const OUString* pLookup = _rPropertyNames.getConstArray(); - const OUString* pLookupEnd = pLookup + nProperties; PropertyState* pStates = aStates.getArray(); cppu::IPropertyArrayHelper& rHelper = getInfoHelper(); Sequence< Property> aAllProperties = rHelper.getProperties(); - sal_Int32 nAllProperties = aAllProperties.getLength(); - const Property* pAllProperties = aAllProperties.getConstArray(); - const Property* pAllPropertiesEnd = pAllProperties + nAllProperties; +#ifdef DBG_UTIL + OSL_ENSURE(std::is_sorted(aAllProperties.begin(), aAllProperties.end(), + [](auto& lhs, auto& rhs) + { return lhs.Name.compareTo(rhs.Name) < 0; }), + "OPropertyStateContainer::getPropertyStates: all-properties not sorted!"); +#endif + auto it = aAllProperties.begin(); + const auto end = aAllProperties.end(); osl::MutexGuard aGuard( rBHelper.rMutex ); - for ( ; ( pAllProperties != pAllPropertiesEnd ) && ( pLookup != pLookupEnd ); ++pAllProperties ) + for (auto& propName : _rPropertyNames) { -#ifdef DBG_UTIL - if ( pAllProperties < pAllPropertiesEnd - 1 ) - OSL_ENSURE( pAllProperties->Name.compareTo( (pAllProperties + 1)->Name ) < 0, - "OPropertyStateContainer::getPropertyStates: all-properties not sorted!" ); -#endif - if ( pAllProperties->Name == *pLookup ) - { - *pStates++ = getPropertyState( *pLookup ); - ++pLookup; - } + it = std::find_if(it, end, [&propName](auto& prop) { return prop.Name == propName; }); + if (it == end) + throw UnknownPropertyException(lcl_getUnknownPropertyErrorMessage(propName), + static_cast(this)); + *pStates++ = getPropertyStateByHandle(it->Handle); } - if ( pLookup != pLookupEnd ) - // we run out of properties from the IPropertyArrayHelper, but still have properties to lookup - // -> we were asked for a nonexistent property - throw UnknownPropertyException( lcl_getUnknownPropertyErrorMessage( *pLookup ), static_cast< XPropertyState* >( this ) ); - return aStates; } diff --git a/comphelper/source/property/propshlp.cxx b/comphelper/source/property/propshlp.cxx index ca1459582827..307f48a42cbc 100644 --- a/comphelper/source/property/propshlp.cxx +++ b/comphelper/source/property/propshlp.cxx @@ -814,7 +814,6 @@ void OPropertySetHelper::firePropertiesChangeEvent( std::unique_ptr pHandles(new sal_Int32[nLen]); IPropertyArrayHelper& rPH = getInfoHelper(); rPH.fillHandles(pHandles.get(), rPropertyNames); - const OUString* pNames = rPropertyNames.getConstArray(); // get the count of matching properties sal_Int32 nFireLen = 0; @@ -836,7 +835,7 @@ void OPropertySetHelper::firePropertiesChangeEvent( if (pHandles[i] != -1) { pChanges[nFirePos].Source = xSource; - pChanges[nFirePos].PropertyName = pNames[i]; + pChanges[nFirePos].PropertyName = rPropertyNames[i]; pChanges[nFirePos].PropertyHandle = pHandles[i]; getFastPropertyValue(aGuard, pChanges[nFirePos].OldValue, pHandles[i]); pChanges[nFirePos].NewValue = pChanges[nFirePos].OldValue; diff --git a/comphelper/source/property/propstate.cxx b/comphelper/source/property/propstate.cxx index 183f51efcedf..20deab1963ee 100644 --- a/comphelper/source/property/propstate.cxx +++ b/comphelper/source/property/propstate.cxx @@ -115,25 +115,22 @@ namespace comphelper sal_Int32 nLen = _rPropertyNames.getLength(); css::uno::Sequence< css::beans::PropertyState> aRet(nLen); css::beans::PropertyState* pValues = aRet.getArray(); - const OUString* pNames = _rPropertyNames.getConstArray(); cppu::IPropertyArrayHelper& rHelper = getInfoHelper(); css::uno::Sequence< css::beans::Property> aProps = rHelper.getProperties(); - const css::beans::Property* pProps = aProps.getConstArray(); - sal_Int32 nPropCount = aProps.getLength(); + auto it = aProps.begin(); + const auto end = aProps.end(); osl::MutexGuard aGuard(rBHelper.rMutex); - for (sal_Int32 i=0, j=0; iName == *pNames) - { - *pValues = getPropertyState(*pNames); - ++pValues; - ++pNames; - ++j; - } + it = std::find_if(it, end, [&propName](auto& prop) { return prop.Name == propName; }); + if (it == end) + break; + *pValues++ = getPropertyStateByHandle(it->Handle); } return aRet; -- 2.11.4.GIT