basic/source/inc/dlgcont.hxx | 8 - basic/source/inc/namecont.hxx | 46 +++------- basic/source/inc/scriptcont.hxx | 7 - basic/source/uno/dlgcont.cxx | 7 - basic/source/uno/namecont.cxx | 182 +++++++++------------------------------- basic/source/uno/scriptcont.cxx | 9 - 6 files changed, 66 insertions(+), 193 deletions(-)
New commits: commit 297b7a7676524ce6d5b3b79764697c5f78970871 Author: Mike Kaganski <[email protected]> AuthorDate: Sun Dec 1 17:08:09 2024 +0500 Commit: Mike Kaganski <[email protected]> CommitDate: Sun Dec 1 16:06:31 2024 +0100 Optimize SfxLibrary / SfxLibraryContainer memory layout a bit Change-Id: I63ba583ef990dd2bbfb7f44af613fce1d8d1b411 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/177608 Tested-by: Jenkins Reviewed-by: Mike Kaganski <[email protected]> diff --git a/basic/source/inc/namecont.hxx b/basic/source/inc/namecont.hxx index aeee51a177fb..75dabc95af1b 100644 --- a/basic/source/inc/namecont.hxx +++ b/basic/source/inc/namecont.hxx @@ -169,8 +169,8 @@ class SfxLibraryContainer VBAScriptListenerContainer maVBAScriptListeners; sal_Int32 mnRunningVBAScripts; bool mbVBACompat; - OUString msProjectName; rtl_TextEncoding meVBATextEncoding; + OUString msProjectName; protected: css::uno::Reference< css::uno::XComponentContext > mxContext; css::uno::Reference< css::ucb::XSimpleFileAccess3 > mxSFI; @@ -180,8 +180,6 @@ protected: ModifiableHelper maModifiable; rtl::Reference<NameContainer> maNameContainer; - bool mbOldInfoFormat; - bool mbOasis2OOoFormat; OUString maInitialDocumentURL; OUString maInfoFileName; @@ -194,6 +192,9 @@ protected: BasicManager* mpBasMgr; bool mbOwnBasMgr; + bool mbOldInfoFormat; + bool mbOasis2OOoFormat; + enum InitMode { DEFAULT, @@ -468,30 +469,25 @@ class SfxLibrary bool mbLoaded; bool mbIsModified; bool mbInitialised; - -private: - - OUString maLibElementFileExtension; - OUString maLibInfoFileURL; - OUString maStorageURL; - OUString maUnexpandedStorageURL; - OUString maOriginalStorageURL; - bool mbLink; bool mbReadOnly; bool mbReadOnlyLink; bool mbPreload; - -protected: bool mbPasswordProtected; -private: bool mbPasswordVerified; bool mbDoc50Password; - OUString maPassword; - bool mbSharedIndexFile; bool mbExtension; +private: + + OUString maLibElementFileExtension; + OUString maLibInfoFileURL; + OUString maStorageURL; + OUString maUnexpandedStorageURL; + OUString maOriginalStorageURL; + OUString maPassword; + // Additional functionality for localisation // Provide modify state including resources virtual bool isModified() = 0; @@ -504,6 +500,7 @@ private: protected: bool implIsModified() const { return mbIsModified; } void implSetModified( bool _bIsModified ); + bool isPasswordProtected() const { return mbPasswordProtected; } private: /** checks whether the lib is readonly, or a readonly link, throws an IllegalArgumentException if so diff --git a/basic/source/uno/namecont.cxx b/basic/source/uno/namecont.cxx index aa979db5061d..4faf47761746 100644 --- a/basic/source/uno/namecont.cxx +++ b/basic/source/uno/namecont.cxx @@ -327,10 +327,10 @@ SfxLibraryContainer::SfxLibraryContainer() , meVBATextEncoding( RTL_TEXTENCODING_DONTKNOW ) , maModifiable( *this, m_aMutex ) , maNameContainer( new NameContainer(cppu::UnoType<XNameAccess>::get()) ) - , mbOldInfoFormat( false ) - , mbOasis2OOoFormat( false ) , mpBasMgr( nullptr ) , mbOwnBasMgr( false ) + , mbOldInfoFormat( false ) + , mbOasis2OOoFormat( false ) , meInitMode(DEFAULT) { mxContext = comphelper::getProcessComponentContext(); @@ -2893,8 +2893,6 @@ SfxLibrary::SfxLibrary( ModifiableHelper& _rModifiable, const Type& aType, , mbLoaded( false ) , mbIsModified( true ) , mbInitialised( false ) - , maLibInfoFileURL(std::move( aLibInfoFileURL )) - , maStorageURL(std::move( aStorageURL )) , mbLink( true ) , mbReadOnly( false ) , mbReadOnlyLink( ReadOnly ) @@ -2904,6 +2902,8 @@ SfxLibrary::SfxLibrary( ModifiableHelper& _rModifiable, const Type& aType, , mbDoc50Password( false ) , mbSharedIndexFile( false ) , mbExtension( false ) + , maLibInfoFileURL(std::move( aLibInfoFileURL )) + , maStorageURL(std::move( aStorageURL )) { } diff --git a/basic/source/uno/scriptcont.cxx b/basic/source/uno/scriptcont.cxx index 9b52d9ffe7e5..41679186c530 100644 --- a/basic/source/uno/scriptcont.cxx +++ b/basic/source/uno/scriptcont.cxx @@ -1146,7 +1146,7 @@ SfxScriptLibrary::SfxScriptLibrary( ModifiableHelper& _rModifiable, bool SfxScriptLibrary::isLoadedStorable() { // note: mbLoadedSource can only be true for password-protected lib! - return SfxLibrary::isLoadedStorable() && (!mbPasswordProtected || mbLoadedSource); + return SfxLibrary::isLoadedStorable() && (!isPasswordProtected() || mbLoadedSource); } // Provide modify state including resources commit d91eca950ef024de7734af9a8de3a208e19b638c Author: Mike Kaganski <[email protected]> AuthorDate: Sun Dec 1 16:50:02 2024 +0500 Commit: Mike Kaganski <[email protected]> CommitDate: Sun Dec 1 16:06:24 2024 +0100 Simplify SfxLibrary hierarchy For some reason, SfxLibrary's own interfaces were used outside of WeakComponentImplHelper; and derived classes didn't use inheritance helper. Change-Id: Ib0b6cf5cfa559fe5eedc4d05247655aca1bfc4b8 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/177607 Reviewed-by: Mike Kaganski <[email protected]> Tested-by: Jenkins Reviewed-by: Noel Grandin <[email protected]> diff --git a/basic/source/inc/dlgcont.hxx b/basic/source/inc/dlgcont.hxx index e66a23701759..81d14d72bec2 100644 --- a/basic/source/inc/dlgcont.hxx +++ b/basic/source/inc/dlgcont.hxx @@ -85,11 +85,10 @@ public: }; -typedef ::cppu::ImplHelper1 < css::resource::XStringResourceSupplier +typedef cppu::ImplInheritanceHelper<SfxLibrary, css::resource::XStringResourceSupplier > SfxDialogLibrary_BASE; -class SfxDialogLibrary final : public SfxLibrary - ,public SfxDialogLibrary_BASE +class SfxDialogLibrary final : public SfxDialogLibrary_BASE { SfxDialogLibraryContainer* m_pParent; css::uno::Reference< css::resource::XStringResourcePersistence> m_xStringResourcePersistence; @@ -122,9 +121,6 @@ public: SfxDialogLibraryContainer* pParent ); - DECLARE_XINTERFACE() - DECLARE_XTYPEPROVIDER() - // XStringResourceSupplier virtual css::uno::Reference< css::resource::XStringResourceResolver > SAL_CALL getStringResource( ) override; diff --git a/basic/source/inc/namecont.hxx b/basic/source/inc/namecont.hxx index e466e714cae0..aeee51a177fb 100644 --- a/basic/source/inc/namecont.hxx +++ b/basic/source/inc/namecont.hxx @@ -453,10 +453,8 @@ public: class SfxLibrary - : public css::container::XNameContainer - , public css::container::XContainer - , public css::util::XChangesNotifier - , public ::comphelper::WeakComponentImplHelper<> + : public comphelper::WeakComponentImplHelper< + css::container::XNameContainer, css::container::XContainer, css::util::XChangesNotifier> { friend class SfxLibraryContainer; friend class SfxDialogLibraryContainer; @@ -534,11 +532,6 @@ public: bool ReadOnly ); - // Methods XInterface - virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type& rType ) override; - virtual void SAL_CALL acquire() noexcept override { WeakComponentImplHelper::acquire(); } - virtual void SAL_CALL release() noexcept override { WeakComponentImplHelper::release(); } - // Methods XElementAccess virtual css::uno::Type SAL_CALL getElementType( ) override; virtual sal_Bool SAL_CALL hasElements( ) override; @@ -555,10 +548,6 @@ public: virtual void SAL_CALL insertByName( const OUString& aName, const css::uno::Any& aElement ) override; virtual void SAL_CALL removeByName( const OUString& Name ) override; - // XTypeProvider - css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override; - css::uno::Sequence<sal_Int8> SAL_CALL getImplementationId( ) override; - // Methods XContainer virtual void SAL_CALL addContainerListener( const css::uno::Reference< css::container::XContainerListener >& xListener ) override; diff --git a/basic/source/inc/scriptcont.hxx b/basic/source/inc/scriptcont.hxx index 2d0e8bcf3232..6d733876fdf4 100644 --- a/basic/source/inc/scriptcont.hxx +++ b/basic/source/inc/scriptcont.hxx @@ -104,9 +104,9 @@ public: typedef std::unordered_map< OUString, css::script::ModuleInfo > ModuleInfoMap; -typedef ::cppu::ImplHelper1< css::script::vba::XVBAModuleInfo > SfxScriptLibrary_BASE; +typedef cppu::ImplInheritanceHelper< SfxLibrary, css::script::vba::XVBAModuleInfo > SfxScriptLibrary_BASE; -class SfxScriptLibrary final : public SfxLibrary, public SfxScriptLibrary_BASE +class SfxScriptLibrary final : public SfxScriptLibrary_BASE { friend class SfxScriptLibraryContainer; @@ -139,9 +139,6 @@ public: const OUString& aLibInfoFileURL, const OUString& aStorageURL, bool ReadOnly ); - DECLARE_XINTERFACE() - DECLARE_XTYPEPROVIDER() - // XVBAModuleInfo virtual css::script::ModuleInfo SAL_CALL getModuleInfo( const OUString& ModuleName ) override; virtual sal_Bool SAL_CALL hasModuleInfo( const OUString& ModuleName ) override; diff --git a/basic/source/uno/dlgcont.cxx b/basic/source/uno/dlgcont.cxx index f2466dabebc7..cf1741aa1506 100644 --- a/basic/source/uno/dlgcont.cxx +++ b/basic/source/uno/dlgcont.cxx @@ -486,7 +486,7 @@ SfxDialogLibrary::SfxDialogLibrary( ModifiableHelper& _rModifiable, OUString aName, const Reference< XSimpleFileAccess3 >& xSFI, SfxDialogLibraryContainer* pParent ) - : SfxLibrary( _rModifiable, cppu::UnoType<XInputStreamProvider>::get(), xSFI ) + : SfxDialogLibrary_BASE(_rModifiable, cppu::UnoType<XInputStreamProvider>::get(), xSFI) , m_pParent( pParent ) , m_aName(std::move( aName )) { @@ -499,16 +499,13 @@ SfxDialogLibrary::SfxDialogLibrary( ModifiableHelper& _rModifiable, const OUString& aStorageURL, bool ReadOnly, SfxDialogLibraryContainer* pParent ) - : SfxLibrary( _rModifiable, cppu::UnoType<XInputStreamProvider>::get(), + : SfxDialogLibrary_BASE(_rModifiable, cppu::UnoType<XInputStreamProvider>::get(), xSFI, aLibInfoFileURL, aStorageURL, ReadOnly) , m_pParent( pParent ) , m_aName(std::move( aName )) { } -IMPLEMENT_FORWARD_XINTERFACE2( SfxDialogLibrary, SfxLibrary, SfxDialogLibrary_BASE ); -IMPLEMENT_FORWARD_XTYPEPROVIDER2( SfxDialogLibrary, SfxLibrary, SfxDialogLibrary_BASE ); - // Provide modify state including resources bool SfxDialogLibrary::isModified() { diff --git a/basic/source/uno/namecont.cxx b/basic/source/uno/namecont.cxx index c50d8be176ea..aa979db5061d 100644 --- a/basic/source/uno/namecont.cxx +++ b/basic/source/uno/namecont.cxx @@ -2925,24 +2925,6 @@ void SfxLibrary::implSetModified( bool _bIsModified ) } } -// Methods XInterface -Any SAL_CALL SfxLibrary::queryInterface( const Type& rType ) -{ - Any aRet = - ::cppu::queryInterface( - rType, - static_cast< XContainer * >( this ), - static_cast< XNameContainer * >( this ), - static_cast< XNameAccess * >( this ), - static_cast< XElementAccess * >( this ), - static_cast< XChangesNotifier * >( this ) ); - if( !aRet.hasValue() ) - { - aRet = WeakComponentImplHelper::queryInterface( rType ); - } - return aRet; -} - // Methods XElementAccess Type SfxLibrary::getElementType() { @@ -3065,24 +3047,6 @@ void SfxLibrary::removeByName( const OUString& Name ) impl_removeWithoutChecks( Name ); } -// XTypeProvider -Sequence< Type > SfxLibrary::getTypes() -{ - static OTypeCollection ourTypes_NameContainer( - cppu::UnoType<XNameContainer>::get(), - cppu::UnoType<XContainer>::get(), - cppu::UnoType<XChangesNotifier>::get(), - WeakComponentImplHelper::getTypes() ); - - return ourTypes_NameContainer.getTypes(); -} - - -Sequence< sal_Int8 > SfxLibrary::getImplementationId() -{ - return css::uno::Sequence<sal_Int8>(); -} - // Methods XContainer void SAL_CALL SfxLibrary::addContainerListener( const Reference< XContainerListener >& xListener ) { diff --git a/basic/source/uno/scriptcont.cxx b/basic/source/uno/scriptcont.cxx index ac755302d261..9b52d9ffe7e5 100644 --- a/basic/source/uno/scriptcont.cxx +++ b/basic/source/uno/scriptcont.cxx @@ -1125,7 +1125,7 @@ Sequence< OUString > SAL_CALL SfxScriptLibraryContainer::getSupportedServiceName // Ctor SfxScriptLibrary::SfxScriptLibrary( ModifiableHelper& _rModifiable, const Reference< XSimpleFileAccess3 >& xSFI ) - : SfxLibrary( _rModifiable, cppu::UnoType<OUString>::get(), xSFI ) + : SfxScriptLibrary_BASE(_rModifiable, cppu::UnoType<OUString>::get(), xSFI) , mbLoadedSource( false ) , mbLoadedBinary( false ) { @@ -1136,7 +1136,7 @@ SfxScriptLibrary::SfxScriptLibrary( ModifiableHelper& _rModifiable, const OUString& aLibInfoFileURL, const OUString& aStorageURL, bool ReadOnly ) - : SfxLibrary( _rModifiable, cppu::UnoType<OUString>::get(), xSFI, + : SfxScriptLibrary_BASE(_rModifiable, cppu::UnoType<OUString>::get(), xSFI, aLibInfoFileURL, aStorageURL, ReadOnly) , mbLoadedSource( false ) , mbLoadedBinary( false ) @@ -1186,9 +1186,6 @@ bool SfxScriptLibrary::isLibraryElementValid(const css::uno::Any& rElement) cons return SfxScriptLibrary::containsValidModule(rElement); } -IMPLEMENT_FORWARD_XINTERFACE2( SfxScriptLibrary, SfxLibrary, SfxScriptLibrary_BASE ); -IMPLEMENT_FORWARD_XTYPEPROVIDER2( SfxScriptLibrary, SfxLibrary, SfxScriptLibrary_BASE ); - script::ModuleInfo SAL_CALL SfxScriptLibrary::getModuleInfo( const OUString& ModuleName ) { if ( !hasModuleInfo( ModuleName ) ) commit ac334d5c76fad666a465508a3704815fa5aaec7c Author: Mike Kaganski <[email protected]> AuthorDate: Sun Dec 1 16:26:38 2024 +0500 Commit: Mike Kaganski <[email protected]> CommitDate: Sun Dec 1 16:06:17 2024 +0100 Simplify a bit Change-Id: Ia48a24d1696aaf2ee7e49f5e8c9f9dcc0ae9e8e2 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/177606 Tested-by: Jenkins Reviewed-by: Mike Kaganski <[email protected]> diff --git a/basic/source/uno/namecont.cxx b/basic/source/uno/namecont.cxx index 714a94e14fdb..c50d8be176ea 100644 --- a/basic/source/uno/namecont.cxx +++ b/basic/source/uno/namecont.cxx @@ -433,13 +433,8 @@ sal_Bool SfxLibraryContainer::isModified() return true; } // the library container is not modified, go through the libraries and check whether they are modified - Sequence< OUString > aNames = maNameContainer->getElementNames(); - const OUString* pNames = aNames.getConstArray(); - sal_Int32 nNameCount = aNames.getLength(); - - for( sal_Int32 i = 0 ; i < nNameCount ; i++ ) + for (auto& aName : maNameContainer->getElementNames()) { - OUString aName = pNames[ i ]; try { SfxLibrary* pImplLib = getImplLib( aName ); @@ -939,12 +934,8 @@ void SfxLibraryContainer::init_Impl( const OUString& rInitialDocumentURL, // Preload? { - Sequence< OUString > aNames = maNameContainer->getElementNames(); - const OUString* pNames = aNames.getConstArray(); - sal_Int32 nNameCount = aNames.getLength(); - for( sal_Int32 i = 0 ; i < nNameCount ; i++ ) + for (auto& aName : maNameContainer->getElementNames()) { - OUString aName = pNames[ i ]; SfxLibrary* pImplLib = getImplLib( aName ); if( pImplLib->mbPreload ) { @@ -1066,13 +1057,8 @@ void SfxLibraryContainer::init_Impl( const OUString& rInitialDocumentURL, mxSFI->move( aFolderUserBasic, aPrevFolder ); mxSFI->move( aFolderTmp, aFolderUserBasic ); - Sequence< OUString > aNames = pPrevCont->getElementNames(); - const OUString* pNames = aNames.getConstArray(); - sal_Int32 nNameCount = aNames.getLength(); - - for( sal_Int32 i = 0 ; i < nNameCount ; i++ ) + for (auto& aLibName : pPrevCont->getElementNames()) { - OUString aLibName = pNames[ i ]; if( hasByName( aLibName ) ) { if( aLibName == aStandardStr ) @@ -1276,11 +1262,8 @@ void SfxLibraryContainer::checkStorageURL( const OUString& aSourceURL, SfxLibrary* SfxLibraryContainer::getImplLib( const OUString& rLibraryName ) { - Any aLibAny = maNameContainer->getByName( rLibraryName ) ; - Reference< XNameAccess > xNameAccess; - aLibAny >>= xNameAccess; - SfxLibrary* pImplLib = static_cast< SfxLibrary* >( xNameAccess.get() ); - return pImplLib; + auto xNameAccess = maNameContainer->getByName(rLibraryName).query<XNameAccess>(); + return static_cast<SfxLibrary*>(xNameAccess.get()); } @@ -1360,15 +1343,10 @@ void SfxLibraryContainer::implStoreLibrary( SfxLibrary* pLib, bool bLink = pLib->mbLink; bool bStorage = xStorage.is() && !bLink; - Sequence< OUString > aElementNames = pLib->getElementNames(); - sal_Int32 nNameCount = aElementNames.getLength(); - const OUString* pNames = aElementNames.getConstArray(); - if( bStorage ) { - for( sal_Int32 i = 0 ; i < nNameCount ; i++ ) + for (auto& aElementName : pLib->getElementNames()) { - OUString aElementName = pNames[ i ]; OUString aStreamName = aElementName + ".xml"; if( !isLibraryElementValid( pLib->getByName( aElementName ) ) ) @@ -1441,10 +1419,8 @@ void SfxLibraryContainer::implStoreLibrary( SfxLibrary* pLib, pLib->storeResources(); } - for( sal_Int32 i = 0 ; i < nNameCount ; i++ ) + for (auto& aElementName : pLib->getElementNames()) { - OUString aElementName = pNames[ i ]; - INetURLObject aElementInetObj( aLibDirPath ); aElementInetObj.insertName( aElementName, false, INetURLObject::LAST_SEGMENT, @@ -1703,12 +1679,10 @@ void SfxLibraryContainer::implImportLibDescriptor( SfxLibrary* pLib, if( pLib->mbInitialised ) return; - sal_Int32 nElementCount = rLib.aElementNames.getLength(); - const OUString* pElementNames = rLib.aElementNames.getConstArray(); Any aDummyElement = createEmptyLibraryElement(); - for( sal_Int32 i = 0 ; i < nElementCount ; i++ ) + for (auto& name : rLib.aElementNames) { - pLib->maNameContainer->insertByName( pElementNames[i], aDummyElement ); + pLib->maNameContainer->insertByName(name, aDummyElement); } pLib->mbPasswordProtected = rLib.bPasswordProtected; pLib->mbReadOnly = rLib.bReadOnly; @@ -1723,20 +1697,14 @@ void SfxLibraryContainer::storeLibraries_Impl( const uno::Reference< embed::XSto bool bComplete ) { const Sequence< OUString > aNames = maNameContainer->getElementNames(); - const sal_Int32 nNameCount = aNames.getLength(); - const OUString* pName = aNames.getConstArray(); - const OUString* pNamesEnd = aNames.getConstArray() + nNameCount; // Don't count libs from shared index file - sal_Int32 nLibsToSave = nNameCount; - for( ; pName != pNamesEnd; ++pName ) - { - SfxLibrary* pImplLib = getImplLib( *pName ); - if( pImplLib->mbSharedIndexFile || pImplLib->mbExtension ) - { - nLibsToSave--; - } - } + sal_Int32 nLibsToSave + = std::count_if(aNames.begin(), aNames.end(), + [this](const OUString& name) { + SfxLibrary* pImplLib = getImplLib(name); + return !pImplLib->mbSharedIndexFile && !pImplLib->mbExtension; + }); // Write to storage? bool bStorage = i_rStorage.is(); uno::Reference< embed::XStorage > xSourceLibrariesStor; @@ -1758,10 +1726,7 @@ void SfxLibraryContainer::storeLibraries_Impl( const uno::Reference< embed::XSto // Don't write if only empty standard lib exists if ( ( nLibsToSave == 1 ) && ( aNames[0] == "Standard" ) ) { - Any aLibAny = maNameContainer->getByName( aNames[0] ); - Reference< XNameAccess > xNameAccess; - aLibAny >>= xNameAccess; - if ( ! xNameAccess->hasElements() ) + if (!getImplLib(aNames[0])->hasElements()) { if ( bInplaceStorage && mxStorage->hasByName(maLibrariesDir) ) { @@ -1825,12 +1790,11 @@ void SfxLibraryContainer::storeLibraries_Impl( const uno::Reference< embed::XSto } int iArray = 0; - pName = aNames.getConstArray(); ::xmlscript::LibDescriptor aLibDescriptorForExtensionLibs; ::xmlscript::LibDescriptorArray aLibArray( nLibsToSave ); - for( ; pName != pNamesEnd; ++pName ) + for (auto& name : aNames) { - SfxLibrary* pImplLib = getImplLib( *pName ); + SfxLibrary* pImplLib = getImplLib(name); if( pImplLib->mbSharedIndexFile ) { continue; @@ -1842,7 +1806,7 @@ void SfxLibraryContainer::storeLibraries_Impl( const uno::Reference< embed::XSto { iArray++; } - rLib.aName = *pName; + rLib.aName = name; rLib.bLink = pImplLib->mbLink; if( !bStorage || pImplLib->mbLink ) @@ -2105,16 +2069,14 @@ Type SAL_CALL SfxLibraryContainer::getElementType() sal_Bool SfxLibraryContainer::hasElements() { LibraryContainerMethodGuard aGuard( *this ); - bool bRet = maNameContainer->hasElements(); - return bRet; + return maNameContainer->hasElements(); } // Methods XNameAccess Any SfxLibraryContainer::getByName( const OUString& aName ) { LibraryContainerMethodGuard aGuard( *this ); - Any aRetAny = maNameContainer->getByName( aName ) ; - return aRetAny; + return maNameContainer->getByName(aName); } Sequence< OUString > SfxLibraryContainer::getElementNames() @@ -2146,8 +2108,7 @@ Reference< XNameContainer > SAL_CALL SfxLibraryContainer::createLibrary( const O aElement <<= xNameAccess; maNameContainer->insertByName( Name, aElement ); maModifiable.setModified( true ); - Reference< XNameContainer > xRet( xNameAccess, UNO_QUERY ); - return xRet; + return pNewLib; } Reference< XNameAccess > SAL_CALL SfxLibraryContainer::createLibraryLink @@ -2199,10 +2160,7 @@ void SAL_CALL SfxLibraryContainer::removeLibrary( const OUString& Name ) { LibraryContainerMethodGuard aGuard( *this ); // Get and hold library before removing - Any aLibAny = maNameContainer->getByName( Name ) ; - Reference< XNameAccess > xNameAccess; - aLibAny >>= xNameAccess; - SfxLibrary* pImplLib = static_cast< SfxLibrary* >( xNameAccess.get() ); + rtl::Reference pImplLib(getImplLib(Name)); if( pImplLib->mbReadOnly && !pImplLib->mbLink ) { throw IllegalArgumentException(u"readonly && !link"_ustr, getXWeak(), 1); @@ -2219,14 +2177,14 @@ void SAL_CALL SfxLibraryContainer::removeLibrary( const OUString& Name ) { return; } - if( xNameAccess->hasElements() ) + if (pImplLib->hasElements()) { for (auto& name : pImplLib->getElementNames()) pImplLib->impl_removeWithoutChecks(name); } // Delete index file - createAppLibraryFolder( pImplLib, Name ); + createAppLibraryFolder(pImplLib.get(), Name); OUString aLibInfoPath = pImplLib->maLibInfoFileURL; try { @@ -2272,14 +2230,11 @@ sal_Bool SAL_CALL SfxLibraryContainer::isLibraryLoaded( const OUString& Name ) void SAL_CALL SfxLibraryContainer::loadLibrary( const OUString& Name ) { LibraryContainerMethodGuard aGuard( *this ); - Any aLibAny = maNameContainer->getByName( Name ) ; - Reference< XNameAccess > xNameAccess; - aLibAny >>= xNameAccess; - SfxLibrary* pImplLib = static_cast< SfxLibrary* >( xNameAccess.get() ); + SfxLibrary* pImplLib = getImplLib(Name); bool bLoaded = pImplLib->mbLoaded; pImplLib->mbLoaded = true; - if( bLoaded || !xNameAccess->hasElements() ) + if (bLoaded || !pImplLib->hasElements()) return; if( pImplLib->mbPasswordProtected ) @@ -2330,13 +2285,8 @@ void SAL_CALL SfxLibraryContainer::loadLibrary( const OUString& Name ) #endif } - Sequence< OUString > aNames = pImplLib->getElementNames(); - sal_Int32 nNameCount = aNames.getLength(); - const OUString* pNames = aNames.getConstArray(); - for( sal_Int32 i = 0 ; i < nNameCount ; i++ ) + for (auto& aElementName : pImplLib->getElementNames()) { - OUString aElementName = pNames[ i ]; - OUString aFile; uno::Reference< io::XInputStream > xInStream; @@ -2468,12 +2418,9 @@ void SAL_CALL SfxLibraryContainer::renameLibrary( const OUString& Name, const OU throw ElementExistException(); } // Get and hold library before removing - Any aLibAny = maNameContainer->getByName( Name ) ; + rtl::Reference pImplLib(getImplLib(Name)); // #i24094 Maybe lib is not loaded! - Reference< XNameAccess > xNameAccess; - aLibAny >>= xNameAccess; - SfxLibrary* pImplLib = static_cast< SfxLibrary* >( xNameAccess.get() ); if( pImplLib->mbPasswordProtected && !pImplLib->mbPasswordVerified ) { return; // Lib with unverified password cannot be renamed @@ -2530,13 +2477,8 @@ void SAL_CALL SfxLibraryContainer::renameLibrary( const OUString& Name, const OU { } - Sequence< OUString > aElementNames = xNameAccess->getElementNames(); - sal_Int32 nNameCount = aElementNames.getLength(); - const OUString* pNames = aElementNames.getConstArray(); - for( sal_Int32 i = 0 ; i < nNameCount ; i++ ) + for (auto& aElementName : pImplLib->getElementNames()) { - OUString aElementName = pNames[ i ]; - INetURLObject aElementInetObj( aLibDirPath ); aElementInetObj.insertName( aElementName, false, INetURLObject::LAST_SEGMENT, INetURLObject::EncodeMechanism::All ); @@ -2589,7 +2531,7 @@ void SAL_CALL SfxLibraryContainer::renameLibrary( const OUString& Name, const OU { // Remove the old library from the container and insert it back with the new name maNameContainer->removeByName(Name); - maNameContainer->insertByName(NewName, aLibAny); + maNameContainer->insertByName(NewName, Any(Reference<XNameAccess>(pImplLib))); maModifiable.setModified(true); } } @@ -3009,8 +2951,7 @@ Type SfxLibrary::getElementType() sal_Bool SfxLibrary::hasElements() { - bool bRet = maNameContainer->hasElements(); - return bRet; + return maNameContainer->hasElements(); } // Methods XNameAccess @@ -3018,8 +2959,7 @@ Any SfxLibrary::getByName( const OUString& aName ) { impl_checkLoaded(); - Any aRetAny = maNameContainer->getByName( aName ) ; - return aRetAny; + return maNameContainer->getByName(aName); } Sequence< OUString > SfxLibrary::getElementNames() @@ -3286,11 +3226,10 @@ Reference< deployment::XPackage > ScriptSubPackageIterator::getNextScriptSubPack } if( m_bIsBundle ) { - const Reference< deployment::XPackage >* pSeq = m_aSubPkgSeq.getConstArray(); sal_Int32 iPkg; for( iPkg = m_iNextSubPkg ; iPkg < m_nSubPkgCount ; ++iPkg ) { - const Reference< deployment::XPackage > xSubPkg = pSeq[ iPkg ]; + const Reference<deployment::XPackage> xSubPkg = m_aSubPkgSeq[iPkg]; xScriptPackage = implDetectScriptPackage( xSubPkg, rbPureDialogLib ); if( xScriptPackage.is() ) { @@ -3362,8 +3301,7 @@ Reference< deployment::XPackage > ScriptExtensionIterator::implGetNextUserScript { if( m_pScriptSubPackageIterator == nullptr ) { - const Reference< deployment::XPackage >* pUserPackages = m_aUserPackagesSeq.getConstArray(); - Reference< deployment::XPackage > xPackage = pUserPackages[ m_iUserPackage ]; + Reference<deployment::XPackage> xPackage = m_aUserPackagesSeq[m_iUserPackage]; SAL_WARN_IF( !xPackage.is(), "basic", ("ScriptExtensionIterator::implGetNextUserScriptPackage():" @@ -3413,8 +3351,7 @@ Reference< deployment::XPackage > ScriptExtensionIterator::implGetNextSharedScri { if( m_pScriptSubPackageIterator == nullptr ) { - const Reference< deployment::XPackage >* pSharedPackages = m_aSharedPackagesSeq.getConstArray(); - Reference< deployment::XPackage > xPackage = pSharedPackages[ m_iSharedPackage ]; + Reference<deployment::XPackage> xPackage = m_aSharedPackagesSeq[m_iSharedPackage]; SAL_WARN_IF( !xPackage.is(), "basic", ("ScriptExtensionIterator::implGetNextSharedScriptPackage():" @@ -3464,8 +3401,7 @@ Reference< deployment::XPackage > ScriptExtensionIterator::implGetNextBundledScr { if( m_pScriptSubPackageIterator == nullptr ) { - const Reference< deployment::XPackage >* pBundledPackages = m_aBundledPackagesSeq.getConstArray(); - Reference< deployment::XPackage > xPackage = pBundledPackages[ m_iBundledPackage ]; + Reference<deployment::XPackage> xPackage = m_aBundledPackagesSeq[m_iBundledPackage]; SAL_WARN_IF( !xPackage.is(), "basic", ("ScriptExtensionIterator::implGetNextBundledScriptPackage():"
