From 9753428dfc2bf038188c9a59af7fd2d789b46517 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Fri, 13 Aug 2021 13:33:08 +0200 Subject: rtl::Static -> thread-safe static local Change-Id: If5b7181fb1bb3f3f21ec3742680e5a3e12b21b73 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/120431 Tested-by: Jenkins Reviewed-by: Noel Grandin --- desktop/source/deployment/misc/dp_resource.cxx | 17 ++-- desktop/source/pkgchk/unopkg/unopkg_misc.cxx | 42 +++++----- .../source/primitive3d/polygontubeprimitive3d.cxx | 22 ++---- editeng/source/editeng/eerdll.cxx | 9 +-- editeng/source/misc/acorrcfg.cxx | 10 +-- editeng/source/uno/unotext.cxx | 91 +++++++--------------- editeng/source/uno/unotext2.cxx | 84 ++++++-------------- filter/source/config/cache/basecontainer.cxx | 10 +-- .../source/config/cache/contenthandlerfactory.cxx | 2 +- filter/source/config/cache/filtercache.hxx | 3 +- filter/source/config/cache/filterfactory.cxx | 10 ++- filter/source/config/cache/frameloaderfactory.cxx | 2 +- filter/source/config/cache/typedetection.cxx | 20 ++--- .../source/xsltdialog/xmlfilterdialogcomponent.cxx | 40 +++------- framework/source/accelerators/keymapping.cxx | 10 +-- framework/source/helper/statusindicatorfactory.cxx | 9 +-- framework/source/layoutmanager/layoutmanager.cxx | 12 +-- framework/source/services/desktop.cxx | 14 ++-- .../source/uiconfiguration/globalsettings.cxx | 13 +--- .../source/uiconfiguration/imagemanagerimpl.cxx | 10 +-- 20 files changed, 136 insertions(+), 294 deletions(-) diff --git a/desktop/source/deployment/misc/dp_resource.cxx b/desktop/source/deployment/misc/dp_resource.cxx index 9e0184291ee0..028f03ae92db 100644 --- a/desktop/source/deployment/misc/dp_resource.cxx +++ b/desktop/source/deployment/misc/dp_resource.cxx @@ -26,24 +26,17 @@ using namespace ::com::sun::star::uno; namespace dp_misc { -namespace +const LanguageTag& getOfficeLanguageTag() { -struct OfficeLocale : public rtl::StaticWithInit -{ - LanguageTag operator()() - { + static const LanguageTag OFFICE_LANG = [&]() { OUString slang(utl::ConfigManager::getUILocale()); //fallback, the locale is currently only set when the user starts the //office for the first time. if (slang.isEmpty()) slang = "en-US"; return LanguageTag(slang); - } -}; - -} // anon namespace - -const LanguageTag& getOfficeLanguageTag() { return OfficeLocale::get(); } + }(); + return OFFICE_LANG; +} } - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/desktop/source/pkgchk/unopkg/unopkg_misc.cxx b/desktop/source/pkgchk/unopkg/unopkg_misc.cxx index 6861f6459cc0..1524ba80a7ab 100644 --- a/desktop/source/pkgchk/unopkg/unopkg_misc.cxx +++ b/desktop/source/pkgchk/unopkg/unopkg_misc.cxx @@ -158,37 +158,31 @@ bool readArgument( } -namespace { -struct ExecutableDir : public rtl::StaticWithInit< - OUString, ExecutableDir> { - OUString operator () () { - OUString path; - if (osl_getExecutableFile( &path.pData ) != osl_Process_E_None) { - throw RuntimeException("cannot locate executable directory!",nullptr); - } - return path.copy( 0, path.lastIndexOf( '/' ) ); - } -}; -struct ProcessWorkingDir : public rtl::StaticWithInit< - OUString, ProcessWorkingDir> { - OUString operator () () { - OUString workingDir; - utl::Bootstrap::getProcessWorkingDir(workingDir); - return workingDir; - } -}; -} // anon namespace - - OUString const & getExecutableDir() { - return ExecutableDir::get(); + static const OUString EXEC = + [&]() + { + OUString path; + if (osl_getExecutableFile( &path.pData ) != osl_Process_E_None) { + throw RuntimeException("cannot locate executable directory!",nullptr); + } + return path.copy( 0, path.lastIndexOf( '/' ) ); + }(); + return EXEC; } OUString const & getProcessWorkingDir() { - return ProcessWorkingDir::get(); + static const OUString WORKING = + [&]() + { + OUString workingDir; + utl::Bootstrap::getProcessWorkingDir(workingDir); + return workingDir; + }(); + return WORKING; } diff --git a/drawinglayer/source/primitive3d/polygontubeprimitive3d.cxx b/drawinglayer/source/primitive3d/polygontubeprimitive3d.cxx index ff00b91050f6..743fb792147f 100644 --- a/drawinglayer/source/primitive3d/polygontubeprimitive3d.cxx +++ b/drawinglayer/source/primitive3d/polygontubeprimitive3d.cxx @@ -105,16 +105,13 @@ namespace drawinglayer::primitive3d } }; - struct theTubeBuffer : - public rtl::Static< TubeBuffer, theTubeBuffer > {}; - Primitive3DContainer getLineTubeSegments( sal_uInt32 nSegments, const attribute::MaterialAttribute3D& rMaterial) { // static data for buffered tube primitives - TubeBuffer &rTheBuffer = theTubeBuffer::get(); - return rTheBuffer.getLineTubeSegments(nSegments, rMaterial); + static TubeBuffer theTubeBuffer; + return theTubeBuffer.getLineTubeSegments(nSegments, rMaterial); } class CapBuffer @@ -183,16 +180,13 @@ namespace drawinglayer::primitive3d } }; - struct theCapBuffer : - public rtl::Static< CapBuffer, theCapBuffer > {}; - Primitive3DContainer getLineCapSegments( sal_uInt32 nSegments, const attribute::MaterialAttribute3D& rMaterial) { // static data for buffered cap primitives - CapBuffer &rTheBuffer = theCapBuffer::get(); - return rTheBuffer.getLineCapSegments(nSegments, rMaterial); + static CapBuffer theCapBuffer; + return theCapBuffer.getLineCapSegments(nSegments, rMaterial); } class CapRoundBuffer @@ -278,17 +272,13 @@ namespace drawinglayer::primitive3d }; - struct theCapRoundBuffer : - public rtl::Static< CapRoundBuffer, theCapRoundBuffer > {}; - - Primitive3DContainer getLineCapRoundSegments( sal_uInt32 nSegments, const attribute::MaterialAttribute3D& rMaterial) { // static data for buffered cap primitives - CapRoundBuffer &rTheBuffer = theCapRoundBuffer::get(); - return rTheBuffer.getLineCapRoundSegments(nSegments, rMaterial); + static CapRoundBuffer theCapRoundBuffer; + return theCapRoundBuffer.getLineCapRoundSegments(nSegments, rMaterial); } Primitive3DContainer getLineJoinSegments( diff --git a/editeng/source/editeng/eerdll.cxx b/editeng/source/editeng/eerdll.cxx index 0e0540bf1244..5e6929ec33a1 100644 --- a/editeng/source/editeng/eerdll.cxx +++ b/editeng/source/editeng/eerdll.cxx @@ -64,19 +64,14 @@ #include #include #include -#include #include using namespace ::com::sun::star; -namespace -{ - class theEditDLL : public rtl::Static {}; -} - EditDLL& EditDLL::Get() { - return theEditDLL::get(); + static EditDLL theEditDLL; + return theEditDLL; } DefItems::DefItems() diff --git a/editeng/source/misc/acorrcfg.cxx b/editeng/source/misc/acorrcfg.cxx index 5489e7d5011f..6d0c0650e416 100644 --- a/editeng/source/misc/acorrcfg.cxx +++ b/editeng/source/misc/acorrcfg.cxx @@ -29,8 +29,6 @@ #include #include -#include - using namespace utl; using namespace com::sun::star; using namespace com::sun::star::uno; @@ -601,14 +599,10 @@ void SvxSwAutoCorrCfg::Notify( const Sequence& /* aPropertyNames */ ) Load(false); } -namespace -{ - class theSvxAutoCorrCfg : public rtl::Static{}; -} - SvxAutoCorrCfg& SvxAutoCorrCfg::Get() { - return theSvxAutoCorrCfg::get(); + static SvxAutoCorrCfg theSvxAutoCorrCfg; + return theSvxAutoCorrCfg; } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/editeng/source/uno/unotext.cxx b/editeng/source/uno/unotext.cxx index 0a3d7f215058..76537f8b425b 100644 --- a/editeng/source/uno/unotext.cxx +++ b/editeng/source/uno/unotext.cxx @@ -28,7 +28,6 @@ #include #include #include -#include #include #include @@ -1548,36 +1547,19 @@ void SAL_CALL SvxUnoTextRange::release() // XTypeProvider -namespace -{ - struct theSvxUnoTextRangeTypes : - public rtl::StaticWithInit, theSvxUnoTextRangeTypes> - { - uno::Sequence operator () () - { - uno::Sequence< uno::Type > aTypeSequence; - - aTypeSequence.realloc( 9 ); // !DANGER! keep this updated - uno::Type* pTypes = aTypeSequence.getArray(); - - *pTypes++ = cppu::UnoType::get(); - *pTypes++ = cppu::UnoType::get(); - *pTypes++ = cppu::UnoType::get(); - *pTypes++ = cppu::UnoType::get(); - *pTypes++ = cppu::UnoType::get(); - *pTypes++ = cppu::UnoType::get(); - *pTypes++ = cppu::UnoType::get(); - *pTypes++ = cppu::UnoType::get(); - *pTypes++ = cppu::UnoType::get(); - - return aTypeSequence; - } - }; -} - uno::Sequence< uno::Type > SAL_CALL SvxUnoTextRange::getTypes() { - return theSvxUnoTextRangeTypes::get(); + static const uno::Sequence< uno::Type > TYPES { + cppu::UnoType::get(), + cppu::UnoType::get(), + cppu::UnoType::get(), + cppu::UnoType::get(), + cppu::UnoType::get(), + cppu::UnoType::get(), + cppu::UnoType::get(), + cppu::UnoType::get(), + cppu::UnoType::get() }; + return TYPES; } uno::Sequence< sal_Int8 > SAL_CALL SvxUnoTextRange::getImplementationId() @@ -1657,42 +1639,25 @@ uno::Any SAL_CALL SvxUnoTextBase::queryAggregation( const uno::Type & rType ) // XTypeProvider -namespace -{ - struct theSvxUnoTextBaseTypes : - public rtl::StaticWithInit, theSvxUnoTextBaseTypes> - { - uno::Sequence operator () () - { - uno::Sequence< uno::Type > aTypeSequence; - - aTypeSequence.realloc( 15 ); // !DANGER! keep this updated - uno::Type* pTypes = aTypeSequence.getArray(); - - *pTypes++ = cppu::UnoType::get(); - *pTypes++ = cppu::UnoType::get(); - *pTypes++ = cppu::UnoType::get(); - *pTypes++ = cppu::UnoType::get(); - *pTypes++ = cppu::UnoType::get(); - *pTypes++ = cppu::UnoType::get(); - *pTypes++ = cppu::UnoType::get(); - *pTypes++ = cppu::UnoType::get(); - *pTypes++ = cppu::UnoType::get(); - *pTypes++ = cppu::UnoType::get(); - *pTypes++ = cppu::UnoType::get(); - *pTypes++ = cppu::UnoType::get(); - *pTypes++ = cppu::UnoType::get(); - *pTypes++ = cppu::UnoType::get(); - *pTypes++ = cppu::UnoType::get(); - - return aTypeSequence; - } - }; -} - uno::Sequence< uno::Type > SAL_CALL SvxUnoTextBase::getTypes() { - return theSvxUnoTextBaseTypes::get(); + static const uno::Sequence< uno::Type > TYPES { + cppu::UnoType::get(), + cppu::UnoType::get(), + cppu::UnoType::get(), + cppu::UnoType::get(), + cppu::UnoType::get(), + cppu::UnoType::get(), + cppu::UnoType::get(), + cppu::UnoType::get(), + cppu::UnoType::get(), + cppu::UnoType::get(), + cppu::UnoType::get(), + cppu::UnoType::get(), + cppu::UnoType::get(), + cppu::UnoType::get(), + cppu::UnoType::get() }; + return TYPES; } uno::Sequence< sal_Int8 > SAL_CALL SvxUnoTextBase::getImplementationId() diff --git a/editeng/source/uno/unotext2.cxx b/editeng/source/uno/unotext2.cxx index f7a2d462e3b3..8ff342d915bb 100644 --- a/editeng/source/uno/unotext2.cxx +++ b/editeng/source/uno/unotext2.cxx @@ -181,38 +181,21 @@ void SAL_CALL SvxUnoTextContent::release() noexcept // XTypeProvider -namespace -{ - struct theSvxUnoTextContentTypes : - public rtl::StaticWithInit, theSvxUnoTextContentTypes> - { - uno::Sequence operator () () - { - uno::Sequence< uno::Type > aTypeSequence; - - aTypeSequence.realloc( 11 ); // !DANGER! keep this updated - uno::Type* pTypes = aTypeSequence.getArray(); - - *pTypes++ = cppu::UnoType::get(); - *pTypes++ = cppu::UnoType::get(); - *pTypes++ = cppu::UnoType::get(); - *pTypes++ = cppu::UnoType::get(); - *pTypes++ = cppu::UnoType::get(); - *pTypes++ = cppu::UnoType::get(); - *pTypes++ = cppu::UnoType::get(); - *pTypes++ = cppu::UnoType::get(); - *pTypes++ = cppu::UnoType::get(); - *pTypes++ = cppu::UnoType::get(); - *pTypes++ = cppu::UnoType::get(); - - return aTypeSequence; - } - }; -} - uno::Sequence< uno::Type > SAL_CALL SvxUnoTextContent::getTypes() { - return theSvxUnoTextContentTypes::get(); + static const uno::Sequence< uno::Type > TYPES { + cppu::UnoType::get(), + cppu::UnoType::get(), + cppu::UnoType::get(), + cppu::UnoType::get(), + cppu::UnoType::get(), + cppu::UnoType::get(), + cppu::UnoType::get(), + cppu::UnoType::get(), + cppu::UnoType::get(), + cppu::UnoType::get(), + cppu::UnoType::get() }; + return TYPES; } uno::Sequence< sal_Int8 > SAL_CALL SvxUnoTextContent::getImplementationId() @@ -501,38 +484,21 @@ void SAL_CALL SvxUnoTextCursor::release() noexcept OWeakAggObject::release(); } -namespace -{ - struct theSvxUnoTextCursorTypes : - public rtl::StaticWithInit, theSvxUnoTextCursorTypes> - { - uno::Sequence operator () () - { - uno::Sequence< uno::Type > aTypeSequence; - - aTypeSequence.realloc( 10 ); // !DANGER! keep this updated - uno::Type* pTypes = aTypeSequence.getArray(); - - *pTypes++ = cppu::UnoType::get(); - *pTypes++ = cppu::UnoType::get(); - *pTypes++ = cppu::UnoType::get(); - *pTypes++ = cppu::UnoType::get(); - *pTypes++ = cppu::UnoType::get(); - *pTypes++ = cppu::UnoType::get(); - *pTypes++ = cppu::UnoType::get(); - *pTypes++ = cppu::UnoType::get(); - *pTypes++ = cppu::UnoType::get(); - *pTypes++ = cppu::UnoType::get(); - - return aTypeSequence; - } - }; -} - // XTypeProvider uno::Sequence< uno::Type > SAL_CALL SvxUnoTextCursor::getTypes() { - return theSvxUnoTextCursorTypes::get(); + static const uno::Sequence< uno::Type > TYPES { + cppu::UnoType::get(), + cppu::UnoType::get(), + cppu::UnoType::get(), + cppu::UnoType::get(), + cppu::UnoType::get(), + cppu::UnoType::get(), + cppu::UnoType::get(), + cppu::UnoType::get(), + cppu::UnoType::get(), + cppu::UnoType::get() }; + return TYPES; } uno::Sequence< sal_Int8 > SAL_CALL SvxUnoTextCursor::getImplementationId() diff --git a/filter/source/config/cache/basecontainer.cxx b/filter/source/config/cache/basecontainer.cxx index 4047f4df2719..023afd29415a 100644 --- a/filter/source/config/cache/basecontainer.cxx +++ b/filter/source/config/cache/basecontainer.cxx @@ -38,7 +38,7 @@ BaseContainer::BaseContainer() , m_eType() , m_lListener (m_aLock) { - TheFilterCache::get().load(FilterCache::E_CONTAINS_STANDARD); + GetTheFilterCache().load(FilterCache::E_CONTAINS_STANDARD); } @@ -93,7 +93,7 @@ void BaseContainer::impl_loadOnDemand() break; } - TheFilterCache::get().load(eRequiredState); + GetTheFilterCache().load(eRequiredState); // <- SAFE #endif } @@ -104,7 +104,7 @@ void BaseContainer::impl_initFlushMode() // SAFE -> osl::MutexGuard aLock(m_aLock); if (!m_pFlushCache) - m_pFlushCache = TheFilterCache::get().clone(); + m_pFlushCache = GetTheFilterCache().clone(); if (!m_pFlushCache) throw css::uno::RuntimeException( "Can not create write copy of internal used cache on demand.", static_cast< OWeakObject* >(this)); @@ -119,7 +119,7 @@ FilterCache* BaseContainer::impl_getWorkingCache() const if (m_pFlushCache) return m_pFlushCache.get(); else - return &TheFilterCache::get(); + return &GetTheFilterCache(); // <- SAFE } @@ -422,7 +422,7 @@ void SAL_CALL BaseContainer::flush() If the global cache gets this information via listener, we should remove this method! */ - TheFilterCache::get().takeOver(*m_pFlushCache); + GetTheFilterCache().takeOver(*m_pFlushCache); } catch(const css::uno::Exception& ex) { diff --git a/filter/source/config/cache/contenthandlerfactory.cxx b/filter/source/config/cache/contenthandlerfactory.cxx index a5140acdbed2..a3bf71cf22ed 100644 --- a/filter/source/config/cache/contenthandlerfactory.cxx +++ b/filter/source/config/cache/contenthandlerfactory.cxx @@ -55,7 +55,7 @@ css::uno::Reference< css::uno::XInterface > SAL_CALL ContentHandlerFactory::crea // SAFE -> osl::MutexGuard aLock(m_aLock); - auto & cache = TheFilterCache::get(); + auto & cache = GetTheFilterCache(); // search handler on cache CacheItem aHandler = cache.getItem(FilterCache::E_CONTENTHANDLER, sHandler); diff --git a/filter/source/config/cache/filtercache.hxx b/filter/source/config/cache/filtercache.hxx index 66d07467f6f3..a0ef79c93931 100644 --- a/filter/source/config/cache/filtercache.hxx +++ b/filter/source/config/cache/filtercache.hxx @@ -29,7 +29,6 @@ #include #include #include -#include #include #include @@ -933,7 +932,7 @@ class FilterCache : public BaseLock static css::uno::Sequence< OUString > impl_convertFlagField2FlagNames(SfxFilterFlags nFlags); }; -struct TheFilterCache: public rtl::Static {}; +FilterCache& GetTheFilterCache(); } // namespace filter::config diff --git a/filter/source/config/cache/filterfactory.cxx b/filter/source/config/cache/filterfactory.cxx index e499b4bad633..8832330d5a04 100644 --- a/filter/source/config/cache/filterfactory.cxx +++ b/filter/source/config/cache/filterfactory.cxx @@ -30,6 +30,12 @@ namespace filter::config{ +FilterCache& GetTheFilterCache() +{ + static FilterCache CACHE; + return CACHE; +} + /** @short define all possible parts of a filter query. @descr syntax: "[:[=]]" @@ -73,7 +79,7 @@ css::uno::Reference< css::uno::XInterface > SAL_CALL FilterFactory::createInstan // SAFE -> osl::MutexGuard aLock(m_aLock); - auto & cache = TheFilterCache::get(); + auto & cache = GetTheFilterCache(); // search filter on cache CacheItem aFilter = cache.getItem(FilterCache::E_FILTER, sFilter); @@ -122,7 +128,7 @@ css::uno::Sequence< OUString > SAL_CALL FilterFactory::getAvailableServiceNames( std::vector lUNOFilters; try { - lUNOFilters = TheFilterCache::get().getMatchingItemsByProps(FilterCache::E_FILTER, lIProps, lEProps); + lUNOFilters = GetTheFilterCache().getMatchingItemsByProps(FilterCache::E_FILTER, lIProps, lEProps); } catch(const css::uno::RuntimeException&) { throw; } diff --git a/filter/source/config/cache/frameloaderfactory.cxx b/filter/source/config/cache/frameloaderfactory.cxx index c7906b4acf1d..a3aef82e4c6c 100644 --- a/filter/source/config/cache/frameloaderfactory.cxx +++ b/filter/source/config/cache/frameloaderfactory.cxx @@ -53,7 +53,7 @@ css::uno::Reference< css::uno::XInterface > SAL_CALL FrameLoaderFactory::createI // SAFE -> osl::MutexGuard aLock(m_aLock); - auto & cache = TheFilterCache::get(); + auto & cache = GetTheFilterCache(); // search loader on cache CacheItem aLoader = cache.getItem(m_eType, sLoader); diff --git a/filter/source/config/cache/typedetection.cxx b/filter/source/config/cache/typedetection.cxx index 34d0d49d5af9..1fd7cccc49ab 100644 --- a/filter/source/config/cache/typedetection.cxx +++ b/filter/source/config/cache/typedetection.cxx @@ -82,7 +82,7 @@ OUString SAL_CALL TypeDetection::queryTypeByURL(const OUString& sURL) // set std types as minimum requirement first! // Only in case no type was found for given URL, // use optional types too ... - auto & cache = TheFilterCache::get(); + auto & cache = GetTheFilterCache(); FlatDetection lFlatTypes; cache.detectFlatForURL(aURL, lFlatTypes); @@ -473,7 +473,7 @@ void TypeDetection::impl_checkResultsAndAddBestFilter(utl::MediaDescriptor& rDes if (!sFilter.isEmpty()) return; - auto & cache = TheFilterCache::get(); + auto & cache = GetTheFilterCache(); // b) // check a preselected document service too. @@ -642,7 +642,7 @@ bool TypeDetection::impl_getPreselectionForType( { // SAFE -> -------------------------- osl::MutexGuard aLock(m_aLock); - aType = TheFilterCache::get().getItem(FilterCache::E_TYPE, sType); + aType = GetTheFilterCache().getItem(FilterCache::E_TYPE, sType); // <- SAFE -------------------------- } catch(const css::container::NoSuchElementException&) @@ -732,7 +732,7 @@ void TypeDetection::impl_getPreselectionForDocumentService( // Attention: For executing next lines of code, We must be sure that // all filters already loaded :-( // That can disturb our "load on demand feature". But we have no other chance! - auto & cache = TheFilterCache::get(); + auto & cache = GetTheFilterCache(); cache.load(FilterCache::E_CONTAINS_FILTERS); CacheItem lIProps; @@ -766,7 +766,7 @@ OUString TypeDetection::impl_getTypeFromFilter(const OUString& rFilterName) try { osl::MutexGuard aLock(m_aLock); - aFilter = TheFilterCache::get().getItem(FilterCache::E_FILTER, rFilterName); + aFilter = GetTheFilterCache().getItem(FilterCache::E_FILTER, rFilterName); } catch (const container::NoSuchElementException&) { @@ -788,7 +788,7 @@ void TypeDetection::impl_getAllFormatTypes( try { osl::MutexGuard aLock(m_aLock); - auto & cache = TheFilterCache::get(); + auto & cache = GetTheFilterCache(); cache.load(FilterCache::E_CONTAINS_FILTERS); aFilterNames = cache.getItemNames(FilterCache::E_FILTER); } @@ -813,7 +813,7 @@ void TypeDetection::impl_getAllFormatTypes( { // Get all types that match the URL alone. FlatDetection aFlatByURL; - TheFilterCache::get().detectFlatForURL(aParsedURL, aFlatByURL); + GetTheFilterCache().detectFlatForURL(aParsedURL, aFlatByURL); for (auto const& elem : aFlatByURL) { FlatDetection::iterator itPos = std::find_if(rFlatTypes.begin(), rFlatTypes.end(), FindByType(elem.sType)); @@ -900,7 +900,7 @@ OUString TypeDetection::impl_detectTypeFlatAndDeep( utl::MediaDescriptor& r { // SAFE -> ---------------------------------- osl::ClearableMutexGuard aLock(m_aLock); - CacheItem aType = TheFilterCache::get().getItem(FilterCache::E_TYPE, sFlatType); + CacheItem aType = GetTheFilterCache().getItem(FilterCache::E_TYPE, sFlatType); aLock.clear(); OUString sDetectService; @@ -1155,7 +1155,7 @@ bool TypeDetection::impl_validateAndSetTypeOnDescriptor( utl::MediaDescript // SAFE -> { osl::MutexGuard aLock(m_aLock); - if (TheFilterCache::get().hasItem(FilterCache::E_TYPE, sType)) + if (GetTheFilterCache().hasItem(FilterCache::E_TYPE, sType)) { rDescriptor[utl::MediaDescriptor::PROP_TYPENAME()] <<= sType; return true; @@ -1177,7 +1177,7 @@ bool TypeDetection::impl_validateAndSetFilterOnDescriptor( utl::MediaDescri // SAFE -> osl::ClearableMutexGuard aLock(m_aLock); - auto & cache = TheFilterCache::get(); + auto & cache = GetTheFilterCache(); CacheItem aFilter = cache.getItem(FilterCache::E_FILTER, sFilter); OUString sType; aFilter[PROPNAME_TYPE] >>= sType; diff --git a/filter/source/xsltdialog/xmlfilterdialogcomponent.cxx b/filter/source/xsltdialog/xmlfilterdialogcomponent.cxx index ec7b04b964fd..095e00e6ab0b 100644 --- a/filter/source/xsltdialog/xmlfilterdialogcomponent.cxx +++ b/filter/source/xsltdialog/xmlfilterdialogcomponent.cxx @@ -31,7 +31,6 @@ #include #include #include -#include #include "xmlfiltersettingsdialog.hxx" @@ -162,42 +161,23 @@ OUString SAL_CALL XMLFilterDialogComponent::getImplementationName() return "com.sun.star.comp.ui.XSLTFilterDialog"; } -namespace { struct lcl_ImplId : public rtl::Static< ::cppu::OImplementationId, lcl_ImplId > {}; } - Sequence< sal_Int8 > SAL_CALL XMLFilterDialogComponent::getImplementationId() { - return css::uno::Sequence(); + static ::cppu::OImplementationId implId; + return implId.getImplementationId(); } -namespace -{ - class DialogComponentTypes - { - private: - OTypeCollection m_aTypes; - public: - DialogComponentTypes() : - m_aTypes( - cppu::UnoType::get(), - cppu::UnoType::get(), - cppu::UnoType::get(), - cppu::UnoType::get(), - cppu::UnoType::get(), - cppu::UnoType::get(), - cppu::UnoType::get(), - cppu::UnoType::get()) - { - } - OTypeCollection& getTypeCollection() { return m_aTypes; } - }; - - struct theDialogComponentTypes : rtl::Static {}; -} - Sequence< Type > XMLFilterDialogComponent::getTypes() { - return theDialogComponentTypes::get().getTypeCollection().getTypes(); + return { cppu::UnoType::get(), + cppu::UnoType::get(), + cppu::UnoType::get(), + cppu::UnoType::get(), + cppu::UnoType::get(), + cppu::UnoType::get(), + cppu::UnoType::get(), + cppu::UnoType::get() }; } Sequence< OUString > SAL_CALL XMLFilterDialogComponent::getSupportedServiceNames() diff --git a/framework/source/accelerators/keymapping.cxx b/framework/source/accelerators/keymapping.cxx index 5f78d6dd65b0..1a5648c8d43a 100644 --- a/framework/source/accelerators/keymapping.cxx +++ b/framework/source/accelerators/keymapping.cxx @@ -21,7 +21,6 @@ #include #include -#include namespace framework { @@ -154,14 +153,9 @@ KeyMapping::KeyMapping() } } -namespace { - -struct Instance: public rtl::Static {}; - -} - KeyMapping & KeyMapping::get() { - return Instance::get(); + static KeyMapping KEYS; + return KEYS; } sal_uInt16 KeyMapping::mapIdentifierToCode(const OUString& sIdentifier) diff --git a/framework/source/helper/statusindicatorfactory.cxx b/framework/source/helper/statusindicatorfactory.cxx index 45c96b373f1a..65cf6141d5ae 100644 --- a/framework/source/helper/statusindicatorfactory.cxx +++ b/framework/source/helper/statusindicatorfactory.cxx @@ -42,12 +42,6 @@ namespace framework{ sal_Int32 StatusIndicatorFactory::m_nInReschedule = 0; ///< static counter for rescheduling -namespace { - -struct RescheduleLock: public rtl::Static {}; ///< mutex to guard the m_nInReschedule - -} - constexpr OUStringLiteral PROGRESS_RESOURCE = u"private:resource/progressbar/progressbar"; StatusIndicatorFactory::StatusIndicatorFactory(const css::uno::Reference< css::uno::XComponentContext >& xContext) @@ -518,8 +512,9 @@ void StatusIndicatorFactory::impl_reschedule(bool bForce) if (!bReschedule) return; + static osl::Mutex rescheduleLock; // SAFE -> - osl::ResettableMutexGuard aRescheduleGuard(RescheduleLock::get()); + osl::ResettableMutexGuard aRescheduleGuard(rescheduleLock); if (m_nInReschedule != 0) return; diff --git a/framework/source/layoutmanager/layoutmanager.cxx b/framework/source/layoutmanager/layoutmanager.cxx index 4d821b4e08ae..b46db52906ff 100644 --- a/framework/source/layoutmanager/layoutmanager.cxx +++ b/framework/source/layoutmanager/layoutmanager.cxx @@ -58,7 +58,6 @@ #include #include #include -#include #include #include @@ -3066,18 +3065,11 @@ namespace detail ::cppu::OPropertyArrayHelper& getHelper() { return *m_pInfoHelper; } }; } -namespace -{ - struct theInfoHelper : - public rtl::StaticWithArg< detail::InfoHelperBuilder, LayoutManager, - theInfoHelper > - { - }; -} ::cppu::IPropertyArrayHelper& SAL_CALL LayoutManager::getInfoHelper() { - return theInfoHelper::get(*this).getHelper(); + static detail::InfoHelperBuilder INFO(*this); + return INFO.getHelper(); } uno::Reference< beans::XPropertySetInfo > SAL_CALL LayoutManager::getPropertySetInfo() diff --git a/framework/source/services/desktop.cxx b/framework/source/services/desktop.cxx index ea2f0cac77f5..c369998365fe 100644 --- a/framework/source/services/desktop.cxx +++ b/framework/source/services/desktop.cxx @@ -51,7 +51,6 @@ #include #include #include -#include #include #include #include @@ -1441,11 +1440,9 @@ void SAL_CALL Desktop::getFastPropertyValue( css::uno::Any& aValue , ::cppu::IPropertyArrayHelper& SAL_CALL Desktop::getInfoHelper() { - struct Static: - public rtl::StaticWithInit - { - cppu::OPropertyArrayHelper operator ()() { - return { + static cppu::OPropertyArrayHelper HELPER = + [&] () { + return cppu::OPropertyArrayHelper { {{"ActiveFrame", PropHandle::ActiveFrame, cppu::UnoType::get(), (css::beans::PropertyAttribute::TRANSIENT @@ -1464,9 +1461,8 @@ void SAL_CALL Desktop::getFastPropertyValue( css::uno::Any& aValue , {"Title", PropHandle::Title, cppu::UnoType::get(), css::beans::PropertyAttribute::TRANSIENT}}, true}; - } - }; - return Static::get(); + }(); + return HELPER; } /*-************************************************************************************************************ diff --git a/framework/source/uiconfiguration/globalsettings.cxx b/framework/source/uiconfiguration/globalsettings.cxx index 2727c2bb24cb..5efaa204274b 100644 --- a/framework/source/uiconfiguration/globalsettings.cxx +++ b/framework/source/uiconfiguration/globalsettings.cxx @@ -25,7 +25,6 @@ #include #include -#include #include #include #include @@ -222,19 +221,9 @@ void GlobalSettings_Access::impl_initConfigAccess() // global class -namespace { - -struct mutexGlobalSettings : public rtl::Static< osl::Mutex, mutexGlobalSettings > {}; - -} - -static rtl::Reference pStaticSettings; - static GlobalSettings_Access* GetGlobalSettings( const css::uno::Reference< css::uno::XComponentContext >& rxContext ) { - osl::MutexGuard aGuard(mutexGlobalSettings::get()); - if ( !pStaticSettings ) - pStaticSettings = new GlobalSettings_Access( rxContext ); + static rtl::Reference pStaticSettings = new GlobalSettings_Access( rxContext ); return pStaticSettings.get(); } diff --git a/framework/source/uiconfiguration/imagemanagerimpl.cxx b/framework/source/uiconfiguration/imagemanagerimpl.cxx index 04ec4db065e1..f479063b4bfc 100644 --- a/framework/source/uiconfiguration/imagemanagerimpl.cxx +++ b/framework/source/uiconfiguration/imagemanagerimpl.cxx @@ -44,7 +44,6 @@ #include #include #include -#include #include using ::com::sun::star::uno::Sequence; @@ -86,15 +85,10 @@ namespace framework static GlobalImageList* pGlobalImageList = nullptr; -namespace -{ - class theGlobalImageListMutex - : public rtl::Static {}; -} - static osl::Mutex& getGlobalImageListMutex() { - return theGlobalImageListMutex::get(); + static osl::Mutex mutex; + return mutex; } static GlobalImageList* getGlobalImageList( const uno::Reference< uno::XComponentContext >& rxContext ) -- cgit