framework/source/uiconfiguration/imagemanagerimpl.cxx | 36 +++++++----- framework/source/uiconfiguration/imagemanagerimpl.hxx | 8 +- i18npool/inc/localedata.hxx | 19 ++++++ i18npool/source/localedata/localedata.cxx | 54 ++++++------------ 4 files changed, 63 insertions(+), 54 deletions(-)
New commits: commit f16fd6725582659602ca8b138937db7283a81bf3 Author: Noel Grandin <noelgran...@gmail.com> AuthorDate: Sat Dec 18 20:43:34 2021 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Mon Dec 20 14:58:10 2021 +0100 flatten LocaleDataImpl a little no need to store LocaleDataLookupTableItem separately Change-Id: I06de28518fe80f6ae1a22c20af2ff32245b66acc Reviewed-on: https://gerrit.libreoffice.org/c/core/+/127112 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/i18npool/inc/localedata.hxx b/i18npool/inc/localedata.hxx index 5e8da5e48ee2..724cbba342a7 100644 --- a/i18npool/inc/localedata.hxx +++ b/i18npool/inc/localedata.hxx @@ -32,6 +32,7 @@ #include <vector> #include <string_view> #include <memory> +#include <optional> #include <osl/module.hxx> @@ -48,6 +49,22 @@ struct LocaleDataLookupTableItem; namespace i18npool { +struct LocaleDataLookupTableItem +{ + const char* dllName; + osl::Module *module; + const char* localeName; + css::lang::Locale aLocale; + + LocaleDataLookupTableItem(const char *name, osl::Module* m, const char* lname) : dllName(name), module(m), localeName(lname) + { + } + bool equals(const css::lang::Locale& rLocale) const + { + return (rLocale == aLocale); + } +}; + class LocaleDataImpl final : public cppu::WeakImplHelper < css::i18n::XLocaleData5, @@ -127,7 +144,7 @@ public: virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override; private: - ::std::unique_ptr< LocaleDataLookupTableItem > cachedItem; + ::std::optional< LocaleDataLookupTableItem > moCachedItem; css::i18n::Calendar2 ref_cal; OUString ref_name; diff --git a/i18npool/source/localedata/localedata.cxx b/i18npool/source/localedata/localedata.cxx index 666858fcb3cf..c85476e01231 100644 --- a/i18npool/source/localedata/localedata.cxx +++ b/i18npool/source/localedata/localedata.cxx @@ -343,22 +343,6 @@ const sal_Unicode cHyphen = '-'; const sal_Int16 nbOfLocales = SAL_N_ELEMENTS(aLibTable); -struct LocaleDataLookupTableItem -{ - const char* dllName; - osl::Module *module; - const char* localeName; - css::lang::Locale aLocale; - - LocaleDataLookupTableItem(const char *name, osl::Module* m, const char* lname) : dllName(name), module(m), localeName(lname) - { - } - bool equals(const css::lang::Locale& rLocale) const - { - return (rLocale == aLocale); - } -}; - namespace i18npool { // static @@ -488,7 +472,7 @@ public: oslGenericFunction getFunctionSymbolByName( const OUString& localeName, const char* pFunction, - std::unique_ptr<LocaleDataLookupTableItem>& rOutCachedItem ); + std::optional<LocaleDataLookupTableItem>& rOutCachedItem ); private: ::osl::Mutex maMutex; @@ -519,7 +503,7 @@ lcl_LookupTableHelper::~lcl_LookupTableHelper() oslGenericFunction lcl_LookupTableHelper::getFunctionSymbolByName( const OUString& localeName, const char* pFunction, - std::unique_ptr<LocaleDataLookupTableItem>& rOutCachedItem ) + std::optional<LocaleDataLookupTableItem>& rOutCachedItem ) { OUString aFallback; bool bFallback = (localeName.indexOf( cUnder) < 0); @@ -546,7 +530,7 @@ oslGenericFunction lcl_LookupTableHelper::getFunctionSymbolByName( { if (rCurrent.dllName == i.pLib) { - rOutCachedItem.reset(new LocaleDataLookupTableItem( rCurrent )); + rOutCachedItem.emplace( rCurrent ); rOutCachedItem->localeName = i.pLocale; OString sSymbolName = OString::Concat(pFunction) + "_" + rOutCachedItem->localeName; @@ -569,7 +553,7 @@ oslGenericFunction lcl_LookupTableHelper::getFunctionSymbolByName( ::osl::MutexGuard aGuard( maMutex ); auto pTmpModule = module.get(); maLookupTable.emplace_back(i.pLib, module.release(), i.pLocale); - rOutCachedItem.reset(new LocaleDataLookupTableItem( maLookupTable.back() )); + rOutCachedItem.emplace( maLookupTable.back() ); OString sSymbolName = OString::Concat(pFunction) + "_" + rOutCachedItem->localeName; return pTmpModule->getFunctionSymbol(sSymbolName.getStr()); } @@ -1427,26 +1411,26 @@ oslGenericFunction LocaleDataImpl::getFunctionSymbol( const Locale& rLocale, con { lcl_LookupTableHelper & rLookupTable = lcl_LookupTableStatic(); - if (cachedItem && cachedItem->equals(rLocale)) + if (moCachedItem && moCachedItem->equals(rLocale)) { OString sSymbolName = OString::Concat(pFunction) + "_" + - cachedItem->localeName; - return cachedItem->module->getFunctionSymbol(sSymbolName.getStr()); + moCachedItem->localeName; + return moCachedItem->module->getFunctionSymbol(sSymbolName.getStr()); } oslGenericFunction pSymbol = nullptr; - std::unique_ptr<LocaleDataLookupTableItem> pCachedItem; + std::optional<LocaleDataLookupTableItem> oCachedItem; // Load function with name <func>_<lang>_<country> or <func>_<bcp47> and // fallbacks. pSymbol = rLookupTable.getFunctionSymbolByName( LocaleDataImpl::getFirstLocaleServiceName( rLocale), - pFunction, pCachedItem); + pFunction, oCachedItem); if (!pSymbol) { ::std::vector< OUString > aFallbacks( LocaleDataImpl::getFallbackLocaleServiceNames( rLocale)); for (const auto& rFallback : aFallbacks) { - pSymbol = rLookupTable.getFunctionSymbolByName(rFallback, pFunction, pCachedItem); + pSymbol = rLookupTable.getFunctionSymbolByName(rFallback, pFunction, oCachedItem); if (pSymbol) break; } @@ -1454,17 +1438,17 @@ oslGenericFunction LocaleDataImpl::getFunctionSymbol( const Locale& rLocale, con if (!pSymbol) { // load default function with name <func>_en_US - pSymbol = rLookupTable.getFunctionSymbolByName("en_US", pFunction, pCachedItem); + pSymbol = rLookupTable.getFunctionSymbolByName("en_US", pFunction, oCachedItem); } if (!pSymbol) // Appropriate symbol could not be found. Give up. throw RuntimeException(); - if (pCachedItem) - cachedItem = std::move(pCachedItem); - if (cachedItem) - cachedItem->aLocale = rLocale; + if (oCachedItem) + moCachedItem = std::move(oCachedItem); + if (moCachedItem) + moCachedItem->aLocale = rLocale; return pSymbol; } @@ -1481,10 +1465,10 @@ LocaleDataImpl::getAllInstalledLocaleNames() // Check if the locale is really available and not just in the table, // don't allow fall backs. - std::unique_ptr<LocaleDataLookupTableItem> pCachedItem; - if (lcl_LookupTableStatic().getFunctionSymbolByName( name, "getLocaleItem", pCachedItem )) { - if( pCachedItem ) - cachedItem = std::move( pCachedItem ); + std::optional<LocaleDataLookupTableItem> oCachedItem; + if (lcl_LookupTableStatic().getFunctionSymbolByName( name, "getLocaleItem", oCachedItem )) { + if( oCachedItem ) + moCachedItem = std::move( oCachedItem ); seqRange[nInstalled++] = LanguageTag::convertToLocale( name.replace( cUnder, cHyphen), false); } } commit 516fa8464f84378f5f6441555689f468ef2e8eb9 Author: Noel Grandin <noelgran...@gmail.com> AuthorDate: Sat Dec 18 20:17:47 2021 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Mon Dec 20 14:58:02 2021 +0100 osl::Mutex->std::mutex in ImageManagerImpl Change-Id: I2feae13f2d8fe90d1f3b072156f3e384fd71db82 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/127108 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/framework/source/uiconfiguration/imagemanagerimpl.cxx b/framework/source/uiconfiguration/imagemanagerimpl.cxx index 47d4e3825cc3..ae8a5b310fcc 100644 --- a/framework/source/uiconfiguration/imagemanagerimpl.cxx +++ b/framework/source/uiconfiguration/imagemanagerimpl.cxx @@ -478,7 +478,6 @@ ImageManagerImpl::ImageManagerImpl( const uno::Reference< uno::XComponentContext m_xContext( rxContext ) , m_pOwner(pOwner) , m_aResourceString( "private:resource/images/moduleimages" ) - , m_aListenerContainer( m_mutex ) , m_bUseGlobal(_bUseGlobal) , m_bReadOnly( true ) , m_bInitialized( false ) @@ -501,7 +500,14 @@ void ImageManagerImpl::dispose() { uno::Reference< uno::XInterface > xOwner(m_pOwner); css::lang::EventObject aEvent( xOwner ); - m_aListenerContainer.disposeAndClear( aEvent ); + { + std::unique_lock aGuard(m_mutex); + m_aEventListeners.disposeAndClear( aGuard, aEvent ); + } + { + std::unique_lock aGuard(m_mutex); + m_aConfigListeners.disposeAndClear( aGuard, aEvent ); + } { SolarMutexGuard g; @@ -530,13 +536,15 @@ void ImageManagerImpl::addEventListener( const uno::Reference< XEventListener >& throw DisposedException(); } - m_aListenerContainer.addInterface( cppu::UnoType<XEventListener>::get(), xListener ); + std::unique_lock aGuard(m_mutex); + m_aEventListeners.addInterface( xListener ); } void ImageManagerImpl::removeEventListener( const uno::Reference< XEventListener >& xListener ) { /* SAFE AREA ----------------------------------------------------------------------------------------------- */ - m_aListenerContainer.removeInterface( cppu::UnoType<XEventListener>::get(), xListener ); + std::unique_lock aGuard(m_mutex); + m_aEventListeners.removeInterface( xListener ); } // XInitialization @@ -1145,23 +1153,21 @@ void ImageManagerImpl::addConfigurationListener( const uno::Reference< css::ui:: throw DisposedException(); } - m_aListenerContainer.addInterface( cppu::UnoType<XUIConfigurationListener>::get(), xListener ); + std::unique_lock aGuard(m_mutex); + m_aConfigListeners.addInterface( xListener ); } void ImageManagerImpl::removeConfigurationListener( const uno::Reference< css::ui::XUIConfigurationListener >& xListener ) { /* SAFE AREA ----------------------------------------------------------------------------------------------- */ - m_aListenerContainer.removeInterface( cppu::UnoType<XUIConfigurationListener>::get(), xListener ); + std::unique_lock aGuard(m_mutex); + m_aConfigListeners.removeInterface( xListener ); } void ImageManagerImpl::implts_notifyContainerListener( const ConfigurationEvent& aEvent, NotifyOp eOp ) { - comphelper::OInterfaceContainerHelper2* pContainer = m_aListenerContainer.getContainer( - cppu::UnoType<css::ui::XUIConfigurationListener>::get()); - if ( pContainer == nullptr ) - return; - - comphelper::OInterfaceIteratorHelper2 pIterator( *pContainer ); + std::unique_lock aGuard(m_mutex); + comphelper::OInterfaceIteratorHelper4 pIterator( m_aConfigListeners ); while ( pIterator.hasMoreElements() ) { try @@ -1169,13 +1175,13 @@ void ImageManagerImpl::implts_notifyContainerListener( const ConfigurationEvent& switch ( eOp ) { case NotifyOp_Replace: - static_cast< css::ui::XUIConfigurationListener*>(pIterator.next())->elementReplaced( aEvent ); + pIterator.next()->elementReplaced( aEvent ); break; case NotifyOp_Insert: - static_cast< css::ui::XUIConfigurationListener*>(pIterator.next())->elementInserted( aEvent ); + pIterator.next()->elementInserted( aEvent ); break; case NotifyOp_Remove: - static_cast< css::ui::XUIConfigurationListener*>(pIterator.next())->elementRemoved( aEvent ); + pIterator.next()->elementRemoved( aEvent ); break; } } diff --git a/framework/source/uiconfiguration/imagemanagerimpl.hxx b/framework/source/uiconfiguration/imagemanagerimpl.hxx index 9bc6f4eb7077..88f4a8349398 100644 --- a/framework/source/uiconfiguration/imagemanagerimpl.hxx +++ b/framework/source/uiconfiguration/imagemanagerimpl.hxx @@ -27,12 +27,13 @@ #include <com/sun/star/embed/XTransactedObject.hpp> #include <cppuhelper/weak.hxx> -#include <comphelper/multicontainer2.hxx> +#include <comphelper/interfacecontainer4.hxx> #include <rtl/ustring.hxx> #include <rtl/ref.hxx> #include <salhelper/simplereferenceobject.hxx> +#include <mutex> #include <unordered_map> #include <vector> @@ -170,8 +171,9 @@ namespace framework std::unique_ptr<CmdImageList> m_pDefaultImageList; OUString m_aModuleIdentifier; OUString m_aResourceString; - osl::Mutex m_mutex; - comphelper::OMultiTypeInterfaceContainerHelper2 m_aListenerContainer; /// container for ALL Listener + std::mutex m_mutex; + comphelper::OInterfaceContainerHelper4<css::lang::XEventListener> m_aEventListeners; + comphelper::OInterfaceContainerHelper4<css::ui::XUIConfigurationListener> m_aConfigListeners; o3tl::enumarray<vcl::ImageType,std::unique_ptr<ImageList>> m_pUserImageList; o3tl::enumarray<vcl::ImageType,bool> m_bUserImageListModified; bool m_bUseGlobal;