From 06ad764cfb36ece7f054ecb786cc0395346a6a68 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Thu, 22 Nov 2018 08:56:15 +0200 Subject: improve function-local statics in scripting..svtools Change-Id: Idf3785a1fbc6fc5b8efbdc4cd363047709f3af91 Reviewed-on: https://gerrit.libreoffice.org/63782 Tested-by: Jenkins Reviewed-by: Noel Grandin --- sd/source/core/stlsheet.cxx | 4 +--- .../ui/framework/factories/BasicViewFactory.cxx | 11 ++++++----- sd/source/ui/unoidl/facreg.cxx | 20 +++++++++----------- 3 files changed, 16 insertions(+), 19 deletions(-) (limited to 'sd') 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& rpDes Reference xResource (rpDescriptor->mxView, UNO_QUERY); if (xResource.is()) { - static ::std::vector > s_aCacheableResources; - if (s_aCacheableResources.empty() ) + static ::std::vector > s_aCacheableResources = [&]() { + ::std::vector > tmp; std::shared_ptr 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 >::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 FactoryMap; namespace { -static std::shared_ptr spFactoryMap; -std::shared_ptr 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 xFactory; uno::Reference xComponentFactory; - const std::shared_ptr& 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) { -- cgit