diff options
-rw-r--r-- | scripting/source/vbaevents/eventhelper.cxx | 11 | ||||
-rw-r--r-- | sd/source/core/stlsheet.cxx | 4 | ||||
-rw-r--r-- | sd/source/ui/framework/factories/BasicViewFactory.cxx | 11 | ||||
-rw-r--r-- | sd/source/ui/unoidl/facreg.cxx | 20 | ||||
-rw-r--r-- | sfx2/source/appl/sfxhelp.cxx | 48 | ||||
-rw-r--r-- | sfx2/source/view/classificationhelper.cxx | 11 | ||||
-rw-r--r-- | sfx2/source/view/sfxbasecontroller.cxx | 74 | ||||
-rw-r--r-- | stoc/source/javaloader/javaloader.cxx | 12 | ||||
-rw-r--r-- | svl/source/misc/inettype.cxx | 18 | ||||
-rw-r--r-- | svtools/source/config/apearcfg.cxx | 15 | ||||
-rw-r--r-- | svtools/source/config/htmlcfg.cxx | 13 |
11 files changed, 88 insertions, 149 deletions
diff --git a/scripting/source/vbaevents/eventhelper.cxx b/scripting/source/vbaevents/eventhelper.cxx index 86d941df9e74..408539cb7038 100644 --- a/scripting/source/vbaevents/eventhelper.cxx +++ b/scripting/source/vbaevents/eventhelper.cxx @@ -256,10 +256,9 @@ static TranslatePropMap aTranslatePropMap_Impl[] = static EventInfoHash& getEventTransInfo() { - static bool initialised = false; - static EventInfoHash eventTransInfo; - if ( !initialised ) + static EventInfoHash eventTransInfo = [&]() { + EventInfoHash tmp; OUString sEventInfo; TranslatePropMap* pTransProp = aTranslatePropMap_Impl; int nCount = SAL_N_ELEMENTS(aTranslatePropMap_Impl); @@ -275,10 +274,10 @@ static EventInfoHash& getEventTransInfo() pTransProp++; i++; }while(i < nCount && sEventInfo == pTransProp->sEventInfo); - eventTransInfo[sEventInfo] = infoList; + tmp[sEventInfo] = infoList; } - initialised = true; - } + return tmp; + }(); return eventTransInfo; } diff --git a/sd/source/core/stlsheet.cxx b/sd/source/core/stlsheet.cxx index 24f365b30936..3df37e99da6e 100644 --- a/sd/source/core/stlsheet.cxx +++ b/sd/source/core/stlsheet.cxx @@ -958,9 +958,7 @@ void SAL_CALL SdStyleSheet::setParentStyle( const OUString& rParentName ) Reference< XPropertySetInfo > SdStyleSheet::getPropertySetInfo() { throwIfDisposed(); - static Reference< XPropertySetInfo > xInfo; - if( !xInfo.is() ) - xInfo = GetStylePropertySet().getPropertySetInfo(); + static Reference< XPropertySetInfo > xInfo = GetStylePropertySet().getPropertySetInfo(); return xInfo; } diff --git a/sd/source/ui/framework/factories/BasicViewFactory.cxx b/sd/source/ui/framework/factories/BasicViewFactory.cxx index 864f305e6009..d76eccbde220 100644 --- a/sd/source/ui/framework/factories/BasicViewFactory.cxx +++ b/sd/source/ui/framework/factories/BasicViewFactory.cxx @@ -439,17 +439,18 @@ bool BasicViewFactory::IsCacheable (const std::shared_ptr<ViewDescriptor>& rpDes Reference<XRelocatableResource> xResource (rpDescriptor->mxView, UNO_QUERY); if (xResource.is()) { - static ::std::vector<Reference<XResourceId> > s_aCacheableResources; - if (s_aCacheableResources.empty() ) + static ::std::vector<Reference<XResourceId> > s_aCacheableResources = [&]() { + ::std::vector<Reference<XResourceId> > tmp; std::shared_ptr<FrameworkHelper> pHelper (FrameworkHelper::Instance(*mpBase)); // The slide sorter and the task panel are cacheable and relocatable. - s_aCacheableResources.push_back(FrameworkHelper::CreateResourceId( + tmp.push_back(FrameworkHelper::CreateResourceId( FrameworkHelper::msSlideSorterURL, FrameworkHelper::msLeftDrawPaneURL)); - s_aCacheableResources.push_back(FrameworkHelper::CreateResourceId( + tmp.push_back(FrameworkHelper::CreateResourceId( FrameworkHelper::msSlideSorterURL, FrameworkHelper::msLeftImpressPaneURL)); - } + return tmp; + }(); ::std::vector<Reference<XResourceId> >::const_iterator iId; for (iId=s_aCacheableResources.begin(); iId!=s_aCacheableResources.end(); ++iId) diff --git a/sd/source/ui/unoidl/facreg.cxx b/sd/source/ui/unoidl/facreg.cxx index 7b69d936ea9e..d4dc0533bfcf 100644 --- a/sd/source/ui/unoidl/facreg.cxx +++ b/sd/source/ui/unoidl/facreg.cxx @@ -44,16 +44,14 @@ enum FactoryId typedef std::unordered_map<OUString, FactoryId> FactoryMap; namespace { -static std::shared_ptr<FactoryMap> spFactoryMap; -std::shared_ptr<FactoryMap> const & GetFactoryMap() +FactoryMap const & GetFactoryMap() { - if (spFactoryMap == nullptr) + static FactoryMap aFactoryMap { - spFactoryMap.reset(new FactoryMap); - (*spFactoryMap)[SdDrawingDocument_getImplementationName()] = SdDrawingDocumentFactoryId; - (*spFactoryMap)[SdPresentationDocument_getImplementationName()] = SdPresentationDocumentFactoryId; - } - return spFactoryMap; + { SdDrawingDocument_getImplementationName(), SdDrawingDocumentFactoryId }, + { SdPresentationDocument_getImplementationName(), SdPresentationDocumentFactoryId } + }; + return aFactoryMap; }; } // end of anonymous namespace @@ -74,10 +72,10 @@ SAL_DLLPUBLIC_EXPORT void * sd_component_getFactory( uno::Reference<lang::XSingleServiceFactory> xFactory; uno::Reference<lang::XSingleComponentFactory> xComponentFactory; - const std::shared_ptr<FactoryMap>& pFactoryMap (GetFactoryMap()); + const FactoryMap& rFactoryMap (GetFactoryMap()); OUString sImplementationName (OUString::createFromAscii(pImplName)); - FactoryMap::const_iterator iFactory (pFactoryMap->find(sImplementationName)); - if (iFactory != pFactoryMap->end()) + FactoryMap::const_iterator iFactory (rFactoryMap.find(sImplementationName)); + if (iFactory != rFactoryMap.end()) { switch (iFactory->second) { diff --git a/sfx2/source/appl/sfxhelp.cxx b/sfx2/source/appl/sfxhelp.cxx index d52f74aa4a96..30aa68b840f4 100644 --- a/sfx2/source/appl/sfxhelp.cxx +++ b/sfx2/source/appl/sfxhelp.cxx @@ -117,25 +117,24 @@ namespace { /// Root path of the help. OUString const & getHelpRootURL() { - static OUString s_instURL; - if (!s_instURL.isEmpty()) - return s_instURL; - - s_instURL = officecfg::Office::Common::Path::Current::Help::get(comphelper::getProcessComponentContext()); - if (s_instURL.isEmpty()) + static OUString const s_instURL = [&]() { - // try to determine path from default - s_instURL = "$(instpath)/" LIBO_SHARE_HELP_FOLDER; - } - - // replace anything like $(instpath); - SvtPathOptions aOptions; - s_instURL = aOptions.SubstituteVariable(s_instURL); + OUString tmp = officecfg::Office::Common::Path::Current::Help::get(comphelper::getProcessComponentContext()); + if (tmp.isEmpty()) + { + // try to determine path from default + tmp = "$(instpath)/" LIBO_SHARE_HELP_FOLDER; + } - OUString url; - if (osl::FileBase::getFileURLFromSystemPath(s_instURL, url) == osl::FileBase::E_None) - s_instURL = url; + // replace anything like $(instpath); + SvtPathOptions aOptions; + tmp = aOptions.SubstituteVariable(tmp); + OUString url; + if (osl::FileBase::getFileURLFromSystemPath(tmp, url) == osl::FileBase::E_None) + tmp = url; + return tmp; + }(); return s_instURL; } @@ -161,13 +160,8 @@ bool impl_hasHelpInstalled() if (comphelper::LibreOfficeKit::isActive()) return false; - static OUString aLocaleStr; - - if (aLocaleStr.isEmpty()) - { // detect installed locale - aLocaleStr = HelpLocaleString(); - } + static OUString const aLocaleStr = HelpLocaleString(); OUString helpRootURL = getHelpRootURL() + "/" + aLocaleStr + "/err.html"; bool bOK = false; @@ -187,13 +181,8 @@ bool impl_hasHTMLHelpInstalled() if (comphelper::LibreOfficeKit::isActive()) return false; - static OUString aLocaleStr; - - if (aLocaleStr.isEmpty()) - { - // detect installed locale - aLocaleStr = HelpLocaleString(); - } + // detect installed locale + static OUString const aLocaleStr = HelpLocaleString(); OUString helpRootURL = getHelpRootURL() + "/" + aLocaleStr + "/text"; bool bOK = impl_checkHelpLocalePath( helpRootURL ); @@ -204,7 +193,6 @@ bool impl_hasHTMLHelpInstalled() } // namespace /// Return the locale we prefer for displaying help -// static OUString const & HelpLocaleString() static OUString const & HelpLocaleString() { if (comphelper::LibreOfficeKit::isActive()) diff --git a/sfx2/source/view/classificationhelper.cxx b/sfx2/source/view/classificationhelper.cxx index 049f8008c4e5..04b414d674c5 100644 --- a/sfx2/source/view/classificationhelper.cxx +++ b/sfx2/source/view/classificationhelper.cxx @@ -762,13 +762,12 @@ sal_Int32 SfxClassificationHelper::GetImpactLevel() } else if (aScale == "FIPS-199") { - static std::map<OUString, sal_Int32> aValues; - if (aValues.empty()) + static std::map<OUString, sal_Int32> const aValues { - aValues["Low"] = 0; - aValues["Moderate"] = 1; - aValues["High"] = 2; - } + { "Low", 0 }, + { "Moderate", 1 }, + { "High", 2 } + }; auto itValues = aValues.find(aLevel); if (itValues == aValues.end()) return nRet; diff --git a/sfx2/source/view/sfxbasecontroller.cxx b/sfx2/source/view/sfxbasecontroller.cxx index a15f07f3831c..697a78450279 100644 --- a/sfx2/source/view/sfxbasecontroller.cxx +++ b/sfx2/source/view/sfxbasecontroller.cxx @@ -113,56 +113,40 @@ struct GroupIDToCommandGroup sal_Int16 const nCommandGroup; }; -static bool bGroupIDMapInitialized = false; -static const GroupIDToCommandGroup GroupIDCommandGroupMap[] = -{ - { SfxGroupId::Intern , frame::CommandGroup::INTERNAL }, - { SfxGroupId::Application , frame::CommandGroup::APPLICATION }, - { SfxGroupId::Document , frame::CommandGroup::DOCUMENT }, - { SfxGroupId::View , frame::CommandGroup::VIEW }, - { SfxGroupId::Edit , frame::CommandGroup::EDIT }, - { SfxGroupId::Macro , frame::CommandGroup::MACRO }, - { SfxGroupId::Options , frame::CommandGroup::OPTIONS }, - { SfxGroupId::Math , frame::CommandGroup::MATH }, - { SfxGroupId::Navigator , frame::CommandGroup::NAVIGATOR }, - { SfxGroupId::Insert , frame::CommandGroup::INSERT }, - { SfxGroupId::Format , frame::CommandGroup::FORMAT }, - { SfxGroupId::Template , frame::CommandGroup::TEMPLATE }, - { SfxGroupId::Text , frame::CommandGroup::TEXT }, - { SfxGroupId::Frame , frame::CommandGroup::FRAME }, - { SfxGroupId::Graphic , frame::CommandGroup::GRAPHIC }, - { SfxGroupId::Table , frame::CommandGroup::TABLE }, - { SfxGroupId::Enumeration , frame::CommandGroup::ENUMERATION }, - { SfxGroupId::Data , frame::CommandGroup::DATA }, - { SfxGroupId::Special , frame::CommandGroup::SPECIAL }, - { SfxGroupId::Image , frame::CommandGroup::IMAGE }, - { SfxGroupId::Chart , frame::CommandGroup::CHART }, - { SfxGroupId::Explorer , frame::CommandGroup::EXPLORER }, - { SfxGroupId::Connector , frame::CommandGroup::CONNECTOR }, - { SfxGroupId::Modify , frame::CommandGroup::MODIFY }, - { SfxGroupId::Drawing , frame::CommandGroup::DRAWING }, - { SfxGroupId::Controls , frame::CommandGroup::CONTROLS }, - { SfxGroupId::NONE, 0 } -}; - typedef std::unordered_map< SfxGroupId, sal_Int16 > GroupHashMap; sal_Int16 MapGroupIDToCommandGroup( SfxGroupId nGroupID ) { - static GroupHashMap s_aHashMap; - - if ( !bGroupIDMapInitialized ) + static GroupHashMap s_aHashMap { - sal_Int32 i = 0; - while ( GroupIDCommandGroupMap[i].nGroupID != SfxGroupId::NONE ) - { - s_aHashMap.emplace( - GroupIDCommandGroupMap[i].nGroupID, - GroupIDCommandGroupMap[i].nCommandGroup ); - ++i; - } - bGroupIDMapInitialized = true; - } + { SfxGroupId::Intern , frame::CommandGroup::INTERNAL }, + { SfxGroupId::Application , frame::CommandGroup::APPLICATION }, + { SfxGroupId::Document , frame::CommandGroup::DOCUMENT }, + { SfxGroupId::View , frame::CommandGroup::VIEW }, + { SfxGroupId::Edit , frame::CommandGroup::EDIT }, + { SfxGroupId::Macro , frame::CommandGroup::MACRO }, + { SfxGroupId::Options , frame::CommandGroup::OPTIONS }, + { SfxGroupId::Math , frame::CommandGroup::MATH }, + { SfxGroupId::Navigator , frame::CommandGroup::NAVIGATOR }, + { SfxGroupId::Insert , frame::CommandGroup::INSERT }, + { SfxGroupId::Format , frame::CommandGroup::FORMAT }, + { SfxGroupId::Template , frame::CommandGroup::TEMPLATE }, + { SfxGroupId::Text , frame::CommandGroup::TEXT }, + { SfxGroupId::Frame , frame::CommandGroup::FRAME }, + { SfxGroupId::Graphic , frame::CommandGroup::GRAPHIC }, + { SfxGroupId::Table , frame::CommandGroup::TABLE }, + { SfxGroupId::Enumeration , frame::CommandGroup::ENUMERATION }, + { SfxGroupId::Data , frame::CommandGroup::DATA }, + { SfxGroupId::Special , frame::CommandGroup::SPECIAL }, + { SfxGroupId::Image , frame::CommandGroup::IMAGE }, + { SfxGroupId::Chart , frame::CommandGroup::CHART }, + { SfxGroupId::Explorer , frame::CommandGroup::EXPLORER }, + { SfxGroupId::Connector , frame::CommandGroup::CONNECTOR }, + { SfxGroupId::Modify , frame::CommandGroup::MODIFY }, + { SfxGroupId::Drawing , frame::CommandGroup::DRAWING }, + { SfxGroupId::Controls , frame::CommandGroup::CONTROLS }, + }; + GroupHashMap::const_iterator pIter = s_aHashMap.find( nGroupID ); if ( pIter != s_aHashMap.end() ) diff --git a/stoc/source/javaloader/javaloader.cxx b/stoc/source/javaloader/javaloader.cxx index 34d80b4f3b52..19dc5d875049 100644 --- a/stoc/source/javaloader/javaloader.cxx +++ b/stoc/source/javaloader/javaloader.cxx @@ -346,16 +346,8 @@ static css::uno::Reference<XInterface> JavaComponentLoader_CreateInstance(const MutexGuard guard( getInitMutex() ); // The javaloader is never destroyed and there can be only one! // Note that the first context wins .... - static css::uno::Reference< XInterface > xStaticRef; - if( xStaticRef.is() ) - { - xRet = xStaticRef; - } - else - { - xRet = *new JavaComponentLoader(xCtx); - xStaticRef = xRet; - } + static css::uno::Reference< XInterface > xStaticRef = *new JavaComponentLoader(xCtx); + xRet = xStaticRef; } catch(const RuntimeException & runtimeException) { SAL_INFO( diff --git a/svl/source/misc/inettype.cxx b/svl/source/misc/inettype.cxx index 3480a55741a3..2704d949a8d5 100644 --- a/svl/source/misc/inettype.cxx +++ b/svl/source/misc/inettype.cxx @@ -19,6 +19,7 @@ #include <sal/config.h> +#include <array> #include <utility> #include <map> @@ -281,17 +282,16 @@ INetContentType INetContentTypes::GetContentType(OUString const & rTypeName) //static OUString INetContentTypes::GetContentType(INetContentType eTypeID) { - static sal_Char const * aMap[CONTENT_TYPE_LAST + 1]; - static bool bInitialized = false; - if (!bInitialized) + static std::array<sal_Char const *, CONTENT_TYPE_LAST + 1> aMap = [&]() { + std::array<sal_Char const *, CONTENT_TYPE_LAST + 1> tmp; for (std::size_t i = 0; i <= CONTENT_TYPE_LAST; ++i) - aMap[aStaticTypeNameMap[i].m_eTypeID] = aStaticTypeNameMap[i].m_pTypeName; - aMap[CONTENT_TYPE_UNKNOWN] = CONTENT_TYPE_STR_APP_OCTSTREAM; - aMap[CONTENT_TYPE_TEXT_PLAIN] = CONTENT_TYPE_STR_TEXT_PLAIN - "; charset=iso-8859-1"; - bInitialized = true; - } + tmp[aStaticTypeNameMap[i].m_eTypeID] = aStaticTypeNameMap[i].m_pTypeName; + tmp[CONTENT_TYPE_UNKNOWN] = CONTENT_TYPE_STR_APP_OCTSTREAM; + tmp[CONTENT_TYPE_TEXT_PLAIN] = CONTENT_TYPE_STR_TEXT_PLAIN + "; charset=iso-8859-1"; + return tmp; + }(); OUString aTypeName = eTypeID <= CONTENT_TYPE_LAST ? OUString::createFromAscii(aMap[eTypeID]) : OUString(); diff --git a/svtools/source/config/apearcfg.cxx b/svtools/source/config/apearcfg.cxx index b98a8cbad17e..4bfe5595012c 100644 --- a/svtools/source/config/apearcfg.cxx +++ b/svtools/source/config/apearcfg.cxx @@ -94,11 +94,8 @@ SvtTabAppearanceCfg::~SvtTabAppearanceCfg( ) const Sequence<OUString>& SvtTabAppearanceCfg::GetPropertyNames() { - static Sequence<OUString> aNames; - if(!aNames.getLength()) + static Sequence<OUString> const aNames { - static const sal_Char* aPropNames[] = - { "Window/Drag" // 0 ,"Menu/FollowMouse" // 1 ,"Dialog/MousePositioning" // 2 @@ -107,15 +104,7 @@ const Sequence<OUString>& SvtTabAppearanceCfg::GetPropertyNames() ,"FontAntiAliasing/Enabled" // 4 ,"FontAntiAliasing/MinPixelHeight" // 5 #endif - }; - const int nCount = SAL_N_ELEMENTS( aPropNames ); - aNames.realloc(nCount); - - const sal_Char** pAsciiNames = aPropNames; - OUString* pNames = aNames.getArray(); - for(int i = 0; i < nCount; ++i, ++pNames, ++pAsciiNames) - *pNames = OUString::createFromAscii( *pAsciiNames ); - } + }; return aNames; } diff --git a/svtools/source/config/htmlcfg.cxx b/svtools/source/config/htmlcfg.cxx index 5fd83ff7027d..7c78ebee4201 100644 --- a/svtools/source/config/htmlcfg.cxx +++ b/svtools/source/config/htmlcfg.cxx @@ -76,11 +76,8 @@ struct HtmlOptions_Impl const Sequence<OUString>& SvxHtmlOptions::GetPropertyNames() { - static Sequence<OUString> aNames; - if(!aNames.getLength()) + static Sequence<OUString> const aNames { - static const char* aPropNames[] = - { "Import/UnknownTag", // 0 "Import/FontSetting", // 1 "Import/FontSize/Size_1", // 2 @@ -97,13 +94,7 @@ const Sequence<OUString>& SvxHtmlOptions::GetPropertyNames() "Export/Warning", // 13 "Export/Encoding", // 14 "Import/NumbersEnglishUS" // 15 - }; - const int nCount = SAL_N_ELEMENTS(aPropNames); - aNames.realloc(nCount); - OUString* pNames = aNames.getArray(); - for(int i = 0; i < nCount; i++) - pNames[i] = OUString::createFromAscii(aPropNames[i]); - } + }; return aNames; } |