diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2019-04-07 11:48:47 +0300 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2019-04-07 17:53:04 +0200 |
commit | 5a824268dfdd48c00f656b767b48cd12ccbdaabb (patch) | |
tree | a25f4afd3ca49cff41fc44559aedea70c82e6c7e /comphelper/source/property | |
parent | a6186a678cd9f67359da885606b3c3983f6bdc74 (diff) |
Don't use resettable/clearable guard where plain guard is enough
Also use scope where possible. This allows to limit guard scope at
language level; visualises the scope clearly; and helps avoiding
errors like fixed in commit 61e4437c857854b331fa01da6f39b2b3b58a800b.
Change-Id: Ifeca96e2df8e8a0897770d9546b2536806275f41
Reviewed-on: https://gerrit.libreoffice.org/70376
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'comphelper/source/property')
-rw-r--r-- | comphelper/source/property/genericpropertyset.cxx | 2 | ||||
-rw-r--r-- | comphelper/source/property/opropertybag.cxx | 63 |
2 files changed, 32 insertions, 33 deletions
diff --git a/comphelper/source/property/genericpropertyset.cxx b/comphelper/source/property/genericpropertyset.cxx index af224f822ede..5ce75e30323a 100644 --- a/comphelper/source/property/genericpropertyset.cxx +++ b/comphelper/source/property/genericpropertyset.cxx @@ -117,7 +117,7 @@ void SAL_CALL GenericPropertySet::addPropertyChangeListener( const OUString& aPr void SAL_CALL GenericPropertySet::removePropertyChangeListener( const OUString& aPropertyName, const Reference< XPropertyChangeListener >& xListener ) { - ResettableMutexGuard aGuard( maMutex ); + ClearableMutexGuard aGuard( maMutex ); Reference < XPropertySetInfo > xInfo = getPropertySetInfo( ); aGuard.clear(); if ( xInfo.is() ) diff --git a/comphelper/source/property/opropertybag.cxx b/comphelper/source/property/opropertybag.cxx index 43dfc4cfdc71..fd5807fae03f 100644 --- a/comphelper/source/property/opropertybag.cxx +++ b/comphelper/source/property/opropertybag.cxx @@ -208,21 +208,21 @@ namespace comphelper if ( !( _element >>= aProperty ) ) throw IllegalArgumentException( OUString(), *this, 1 ); - ::osl::ClearableMutexGuard g( m_aMutex ); - - // check whether the type is allowed, everything else will be checked - // by m_aDynamicProperties - if ( !m_aAllowedTypes.empty() - && m_aAllowedTypes.find( aProperty.Type ) == m_aAllowedTypes.end() - ) - throw IllegalArgumentException( OUString(), *this, 1 ); + { + osl::MutexGuard g(m_aMutex); - m_aDynamicProperties.addVoidProperty( aProperty.Name, aProperty.Type, findFreeHandle(), aProperty.Attributes ); + // check whether the type is allowed, everything else will be checked + // by m_aDynamicProperties + if (!m_aAllowedTypes.empty() + && m_aAllowedTypes.find(aProperty.Type) == m_aAllowedTypes.end()) + throw IllegalArgumentException(OUString(), *this, 1); - // our property info is dirty - m_pArrayHelper.reset(); + m_aDynamicProperties.addVoidProperty(aProperty.Name, aProperty.Type, findFreeHandle(), + aProperty.Attributes); - g.clear(); + // our property info is dirty + m_pArrayHelper.reset(); + } setModified(true); } @@ -312,37 +312,36 @@ namespace comphelper void SAL_CALL OPropertyBag::addProperty( const OUString& _rName, ::sal_Int16 _nAttributes, const Any& _rInitialValue ) { - ::osl::ClearableMutexGuard g( m_aMutex ); - - // check whether the type is allowed, everything else will be checked - // by m_aDynamicProperties - const Type& aPropertyType = _rInitialValue.getValueType(); - if ( _rInitialValue.hasValue() - && !m_aAllowedTypes.empty() - && m_aAllowedTypes.find( aPropertyType ) == m_aAllowedTypes.end() - ) - throw IllegalTypeException( OUString(), *this ); + { + osl::MutexGuard g(m_aMutex); - m_aDynamicProperties.addProperty( _rName, findFreeHandle(), _nAttributes, _rInitialValue ); + // check whether the type is allowed, everything else will be checked + // by m_aDynamicProperties + const Type& aPropertyType = _rInitialValue.getValueType(); + if (_rInitialValue.hasValue() && !m_aAllowedTypes.empty() + && m_aAllowedTypes.find(aPropertyType) == m_aAllowedTypes.end()) + throw IllegalTypeException(OUString(), *this); - // our property info is dirty - m_pArrayHelper.reset(); + m_aDynamicProperties.addProperty(_rName, findFreeHandle(), _nAttributes, + _rInitialValue); - g.clear(); + // our property info is dirty + m_pArrayHelper.reset(); + } setModified(true); } void SAL_CALL OPropertyBag::removeProperty( const OUString& _rName ) { - ::osl::ClearableMutexGuard g( m_aMutex ); - - m_aDynamicProperties.removeProperty( _rName ); + { + osl::MutexGuard g(m_aMutex); - // our property info is dirty - m_pArrayHelper.reset(); + m_aDynamicProperties.removeProperty(_rName); - g.clear(); + // our property info is dirty + m_pArrayHelper.reset(); + } setModified(true); } |