From 852956a271578b9ad7c1ef2983381e109f2a8156 Mon Sep 17 00:00:00 2001 From: Maarten Bosmans Date: Sun, 25 Sep 2016 20:28:53 +0200 Subject: tdf#43544 ScStyleObj: Only call StylePool->find() when necessary Avoid repeatedly calling GetStyle() when setting/getting multiple properties. By caching the SfxStyleSheet before entering the loop over all properties, performance of loading the document attached to tdf#43544 improves by 12%. Change-Id: Ic3f1314892b4771aa87801b63f854f83ec761d41 Reviewed-on: https://gerrit.libreoffice.org/29274 Reviewed-by: Eike Rathke Tested-by: Eike Rathke (cherry picked from commit 9d99a7b2d1dd973b50a699440ffb69d99d614607) Reviewed-on: https://gerrit.libreoffice.org/31319 --- sc/source/ui/unoobj/styleuno.cxx | 202 +++++++++++++++++++-------------------- 1 file changed, 96 insertions(+), 106 deletions(-) (limited to 'sc/source/ui') diff --git a/sc/source/ui/unoobj/styleuno.cxx b/sc/source/ui/unoobj/styleuno.cxx index 763ff041b097..f0a2be6d4cdf 100644 --- a/sc/source/ui/unoobj/styleuno.cxx +++ b/sc/source/ui/unoobj/styleuno.cxx @@ -582,11 +582,8 @@ void ScStyleFamiliesObj::loadStylesFromDocShell( ScDocShell* pSource, bool bLoadCellStyles = true; bool bLoadPageStyles = true; - const beans::PropertyValue* pPropArray = aOptions.getConstArray(); - long nPropCount = aOptions.getLength(); - for (long i = 0; i < nPropCount; i++) + for ( const beans::PropertyValue& rProp : aOptions ) { - const beans::PropertyValue& rProp = pPropArray[i]; OUString aPropName(rProp.Name); if (aPropName == SC_UNONAME_OVERWSTL) @@ -1016,15 +1013,18 @@ void ScStyleObj::Notify( SfxBroadcaster&, const SfxHint& rHint ) } } -SfxStyleSheetBase* ScStyleObj::GetStyle_Impl() +SfxStyleSheetBase* ScStyleObj::GetStyle_Impl( bool useCachedValue ) { + if ( useCachedValue ) + return pStyle_cached; + pStyle_cached = nullptr; if ( pDocShell ) { ScDocument& rDoc = pDocShell->GetDocument(); ScStyleSheetPool* pStylePool = rDoc.GetStyleSheetPool(); - return pStylePool->Find( aStyleName, eFamily ); + pStyle_cached = pStylePool->Find( aStyleName, eFamily ); } - return nullptr; + return pStyle_cached; } // style::XStyle @@ -1162,12 +1162,10 @@ uno::Reference ScStyleObj::CreateEmptyNumberingRules() // beans::XPropertyState const SfxItemSet* ScStyleObj::GetStyleItemSet_Impl( const OUString& rPropName, - const SfxItemPropertySimpleEntry*& rpResultEntry ) + const SfxItemPropertySimpleEntry*& rpResultEntry ) { - //! OUString as argument? - - SfxStyleSheetBase* pStyle = GetStyle_Impl(); - if (pStyle) + SfxStyleSheetBase* pStyle = GetStyle_Impl( true ); + if ( pStyle ) { const SfxItemPropertySimpleEntry* pEntry = nullptr; if ( eFamily == SfxStyleFamily::Page ) @@ -1197,10 +1195,9 @@ const SfxItemSet* ScStyleObj::GetStyleItemSet_Impl( const OUString& rPropName, return nullptr; } -beans::PropertyState SAL_CALL ScStyleObj::getPropertyState( const OUString& aPropertyName ) - throw(beans::UnknownPropertyException, uno::RuntimeException, std::exception) +beans::PropertyState ScStyleObj::getPropertyState_Impl( const OUString& aPropertyName ) + throw(beans::UnknownPropertyException, uno::RuntimeException, std::exception) { - SolarMutexGuard aGuard; beans::PropertyState eRet = beans::PropertyState_DIRECT_VALUE; const SfxItemPropertySimpleEntry* pResultEntry = nullptr; @@ -1237,19 +1234,25 @@ beans::PropertyState SAL_CALL ScStyleObj::getPropertyState( const OUString& aPro return eRet; } -uno::Sequence SAL_CALL ScStyleObj::getPropertyStates( - const uno::Sequence& aPropertyNames ) - throw(beans::UnknownPropertyException, uno::RuntimeException, std::exception) +beans::PropertyState SAL_CALL ScStyleObj::getPropertyState( const OUString& aPropertyName ) + throw(beans::UnknownPropertyException, uno::RuntimeException, std::exception) { - // duemmliche Default-Implementierung: alles einzeln per getPropertyState holen - //! sollte optimiert werden! + SolarMutexGuard aGuard; + GetStyle_Impl(); + + return getPropertyState_Impl( aPropertyName ); +} +uno::Sequence SAL_CALL ScStyleObj::getPropertyStates( const uno::Sequence& aPropertyNames ) + throw(beans::UnknownPropertyException, uno::RuntimeException, std::exception) +{ SolarMutexGuard aGuard; - const OUString* pNames = aPropertyNames.getConstArray(); - uno::Sequence aRet(aPropertyNames.getLength()); + GetStyle_Impl(); + + uno::Sequence aRet( aPropertyNames.getLength() ); beans::PropertyState* pStates = aRet.getArray(); - for(sal_Int32 i = 0; i < aPropertyNames.getLength(); i++) - pStates[i] = getPropertyState(pNames[i]); + for ( sal_Int32 i = 0; i < aPropertyNames.getLength(); i++ ) + pStates[i] = getPropertyState_Impl( aPropertyNames[i] ); return aRet; } @@ -1258,20 +1261,18 @@ void SAL_CALL ScStyleObj::setPropertyToDefault( const OUString& aPropertyName ) std::exception) { SolarMutexGuard aGuard; + GetStyle_Impl(); - const SfxItemPropertyMap& rMap = pPropSet->getPropertyMap(); - const SfxItemPropertySimpleEntry* pEntry = rMap.getByName( aPropertyName ); + const SfxItemPropertySimpleEntry* pEntry = pPropSet->getPropertyMap().getByName( aPropertyName ); if ( !pEntry ) throw beans::UnknownPropertyException(); - SetOnePropertyValue( aPropertyName, pEntry, nullptr ); + setPropertyValue_Impl( aPropertyName, pEntry, nullptr ); } -uno::Any SAL_CALL ScStyleObj::getPropertyDefault( const OUString& aPropertyName ) - throw(beans::UnknownPropertyException, lang::WrappedTargetException, - uno::RuntimeException, std::exception) +uno::Any ScStyleObj::getPropertyDefault_Impl( const OUString& aPropertyName ) + throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception) { - SolarMutexGuard aGuard; uno::Any aAny; const SfxItemPropertySimpleEntry* pResultEntry = nullptr; @@ -1356,6 +1357,28 @@ uno::Any SAL_CALL ScStyleObj::getPropertyDefault( const OUString& aPropertyName return aAny; } +uno::Any SAL_CALL ScStyleObj::getPropertyDefault( const OUString& aPropertyName ) + throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception) +{ + SolarMutexGuard aGuard; + GetStyle_Impl(); + + return getPropertyDefault_Impl( aPropertyName ); +} + +uno::Sequence SAL_CALL ScStyleObj::getPropertyDefaults( const uno::Sequence& aPropertyNames ) + throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception) +{ + SolarMutexGuard aGuard; + GetStyle_Impl(); + + uno::Sequence aSequence( aPropertyNames.getLength() ); + uno::Any* pValues = aSequence.getArray(); + for ( sal_Int32 i = 0; i < aPropertyNames.getLength(); i++ ) + pValues[i] = getPropertyDefault_Impl( aPropertyNames[i] ); + return aSequence; +} + // XMultiPropertySet void SAL_CALL ScStyleObj::setPropertyValues( const uno::Sequence< OUString >& aPropertyNames, @@ -1365,41 +1388,31 @@ throw (beans::PropertyVetoException, lang::IllegalArgumentException, std::exception) { SolarMutexGuard aGuard; + GetStyle_Impl(); - sal_Int32 nCount = aPropertyNames.getLength(); - if ( aValues.getLength() != nCount ) + if ( aValues.getLength() != aPropertyNames.getLength() ) throw lang::IllegalArgumentException(); - if ( nCount ) + const OUString* pNames = aPropertyNames.getConstArray(); + const uno::Any* pValues = aValues.getConstArray(); + const SfxItemPropertyMap& rPropertyMap = pPropSet->getPropertyMap(); + for ( sal_Int32 i = 0; i < aPropertyNames.getLength(); i++ ) { - const OUString* pNames = aPropertyNames.getConstArray(); - const uno::Any* pValues = aValues.getConstArray(); - - const SfxItemPropertyMap& rPropertyMap = pPropSet->getPropertyMap(); - for (sal_Int32 i = 0; i < nCount; i++) - { - const SfxItemPropertySimpleEntry* pEntry = rPropertyMap.getByName( pNames[i] ); - SetOnePropertyValue( pNames[i], pEntry, &pValues[i] ); - } + const SfxItemPropertySimpleEntry* pEntry = rPropertyMap.getByName( pNames[i] ); + setPropertyValue_Impl( pNames[i], pEntry, &pValues[i] ); } } -uno::Sequence SAL_CALL ScStyleObj::getPropertyValues( - const uno::Sequence< OUString >& aPropertyNames ) - throw (uno::RuntimeException, std::exception) +uno::Sequence SAL_CALL ScStyleObj::getPropertyValues( const uno::Sequence< OUString >& aPropertyNames ) + throw (uno::RuntimeException, std::exception) { SolarMutexGuard aGuard; + GetStyle_Impl(); - //! optimize - - sal_Int32 nCount = aPropertyNames.getLength(); - uno::Sequence aSequence( nCount ); - if ( nCount ) - { - uno::Any* pValues = aSequence.getArray(); - for (sal_Int32 i=0; i aSequence( aPropertyNames.getLength() ); + uno::Any* pValues = aSequence.getArray(); + for ( sal_Int32 i = 0; i < aPropertyNames.getLength(); i++ ) + pValues[i] = getPropertyValue_Impl( aPropertyNames[i] ); return aSequence; } @@ -1478,43 +1491,18 @@ void SAL_CALL ScStyleObj::setAllPropertiesToDefault() } void SAL_CALL ScStyleObj::setPropertiesToDefault( const uno::Sequence& aPropertyNames ) - throw (beans::UnknownPropertyException, uno::RuntimeException, - std::exception) -{ - SolarMutexGuard aGuard; - - sal_Int32 nCount = aPropertyNames.getLength(); - if ( nCount ) - { - const OUString* pNames = aPropertyNames.getConstArray(); - - const SfxItemPropertyMap& rPropertyMap = pPropSet->getPropertyMap(); - for (sal_Int32 i = 0; i < nCount; i++) - { - const SfxItemPropertySimpleEntry* pEntry = rPropertyMap.getByName( pNames[i] ); - SetOnePropertyValue( pNames[i], pEntry, nullptr ); - } - } -} - -uno::Sequence SAL_CALL ScStyleObj::getPropertyDefaults( - const uno::Sequence& aPropertyNames ) - throw (beans::UnknownPropertyException, lang::WrappedTargetException, - uno::RuntimeException, std::exception) + throw (beans::UnknownPropertyException, uno::RuntimeException, std::exception) { SolarMutexGuard aGuard; + GetStyle_Impl(); - //! optimize - - sal_Int32 nCount = aPropertyNames.getLength(); - uno::Sequence aSequence( nCount ); - if ( nCount ) + const OUString* pNames = aPropertyNames.getConstArray(); + const SfxItemPropertyMap& rPropertyMap = pPropSet->getPropertyMap(); + for ( sal_Int32 i = 0; i < aPropertyNames.getLength(); i++ ) { - uno::Any* pValues = aSequence.getArray(); - for (sal_Int32 i=0; i SAL_CALL ScStyleObj::getPropertySetInfo( return pPropSet->getPropertySetInfo(); } -void SAL_CALL ScStyleObj::setPropertyValue( - const OUString& aPropertyName, const uno::Any& aValue ) +void SAL_CALL ScStyleObj::setPropertyValue( const OUString& aPropertyName, const uno::Any& aValue ) throw(beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException, std::exception) { SolarMutexGuard aGuard; + GetStyle_Impl(); const SfxItemPropertySimpleEntry* pEntry = pPropSet->getPropertyMap().getByName( aPropertyName ); if ( !pEntry ) throw beans::UnknownPropertyException(); - SetOnePropertyValue( aPropertyName, pEntry, &aValue ); + setPropertyValue_Impl( aPropertyName, pEntry, &aValue ); } -void ScStyleObj::SetOnePropertyValue( const OUString& rPropertyName, const SfxItemPropertySimpleEntry* pEntry, const uno::Any* pValue ) - throw(lang::IllegalArgumentException, - uno::RuntimeException, - std::exception) +void ScStyleObj::setPropertyValue_Impl( const OUString& rPropertyName, const SfxItemPropertySimpleEntry* pEntry, const uno::Any* pValue ) + throw(lang::IllegalArgumentException, uno::RuntimeException, std::exception) { - SfxStyleSheetBase* pStyle = GetStyle_Impl(); + SfxStyleSheetBase* pStyle = GetStyle_Impl( true ); if ( pStyle && pEntry ) { // cell styles cannot be modified if any sheet is protected @@ -1851,18 +1837,16 @@ void ScStyleObj::SetOnePropertyValue( const OUString& rPropertyName, const SfxIt } } -uno::Any SAL_CALL ScStyleObj::getPropertyValue( const OUString& aPropertyName ) - throw(beans::UnknownPropertyException, lang::WrappedTargetException, - uno::RuntimeException, std::exception) +uno::Any ScStyleObj::getPropertyValue_Impl( const OUString& aPropertyName ) + throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception) { - SolarMutexGuard aGuard; uno::Any aAny; + SfxStyleSheetBase* pStyle = GetStyle_Impl( true ); if ( aPropertyName == SC_UNONAME_DISPNAME ) // read-only { // core always has the display name - SfxStyleSheetBase* pStyle = GetStyle_Impl(); - if (pStyle) + if ( pStyle ) aAny <<= OUString( pStyle->GetName() ); } else @@ -1940,10 +1924,7 @@ uno::Any SAL_CALL ScStyleObj::getPropertyValue( const OUString& aPropertyName ) break; case ATTR_HIDDEN: { - bool bHidden = false; - SfxStyleSheetBase* pStyle = GetStyle_Impl(); - if ( pStyle ) - bHidden = pStyle->IsHidden(); + bool bHidden = pStyle && pStyle->IsHidden(); aAny = uno::makeAny( bHidden ); } break; @@ -1988,6 +1969,15 @@ uno::Any SAL_CALL ScStyleObj::getPropertyValue( const OUString& aPropertyName ) return aAny; } +uno::Any SAL_CALL ScStyleObj::getPropertyValue( const OUString& aPropertyName ) + throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception) +{ + SolarMutexGuard aGuard; + GetStyle_Impl(); + + return getPropertyValue_Impl( aPropertyName ); +} + SC_IMPL_DUMMY_PROPERTY_LISTENER( ScStyleObj ) // lang::XServiceInfo -- cgit