From 2e6a38b7f007b36719f5fc002cb4363dec45e0d4 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Wed, 21 Nov 2018 11:47:47 +0200 Subject: improve function-local statics in dbaccess..filter Change-Id: I64939ad4b6c53696e33300114db384abfe73f13f Reviewed-on: https://gerrit.libreoffice.org/63702 Tested-by: Jenkins Reviewed-by: Noel Grandin --- dbaccess/source/filter/xml/xmlDataSourceSetting.cxx | 21 +++++++++++---------- dbaccess/source/filter/xml/xmlservices.cxx | 9 +++++---- dbaccess/source/ui/misc/dsmeta.cxx | 18 ++++++++++-------- dbaccess/source/ui/misc/uiservices.cxx | 9 +++++---- 4 files changed, 31 insertions(+), 26 deletions(-) (limited to 'dbaccess') diff --git a/dbaccess/source/filter/xml/xmlDataSourceSetting.cxx b/dbaccess/source/filter/xml/xmlDataSourceSetting.cxx index 107cbe700390..e5defb425a0e 100644 --- a/dbaccess/source/filter/xml/xmlDataSourceSetting.cxx +++ b/dbaccess/source/filter/xml/xmlDataSourceSetting.cxx @@ -70,18 +70,19 @@ OXMLDataSourceSetting::OXMLDataSourceSetting( ODBFilter& rImport case XML_TOK_DATA_SOURCE_SETTING_TYPE: { // needs to be translated into a css::uno::Type - static std::map< OUString, css::uno::Type > s_aTypeNameMap; - if (s_aTypeNameMap.empty()) + static std::map< OUString, css::uno::Type > s_aTypeNameMap = [&]() { - s_aTypeNameMap[GetXMLToken( XML_BOOLEAN)] = cppu::UnoType::get(); + std::map< OUString, css::uno::Type > tmp; + tmp[GetXMLToken( XML_BOOLEAN)] = cppu::UnoType::get(); // Not a copy paste error, see comment xmloff/source/forms/propertyimport.cxx lines 244-248 - s_aTypeNameMap[GetXMLToken( XML_FLOAT)] = ::cppu::UnoType::get(); - s_aTypeNameMap[GetXMLToken( XML_DOUBLE)] = ::cppu::UnoType::get(); - s_aTypeNameMap[GetXMLToken( XML_STRING)] = ::cppu::UnoType::get(); - s_aTypeNameMap[GetXMLToken( XML_INT)] = ::cppu::UnoType::get(); - s_aTypeNameMap[GetXMLToken( XML_SHORT)] = ::cppu::UnoType::get(); - s_aTypeNameMap[GetXMLToken( XML_VOID)] = cppu::UnoType::get(); - } + tmp[GetXMLToken( XML_FLOAT)] = ::cppu::UnoType::get(); + tmp[GetXMLToken( XML_DOUBLE)] = ::cppu::UnoType::get(); + tmp[GetXMLToken( XML_STRING)] = ::cppu::UnoType::get(); + tmp[GetXMLToken( XML_INT)] = ::cppu::UnoType::get(); + tmp[GetXMLToken( XML_SHORT)] = ::cppu::UnoType::get(); + tmp[GetXMLToken( XML_VOID)] = cppu::UnoType::get(); + return tmp; + }(); const std::map< OUString, css::uno::Type >::const_iterator aTypePos = s_aTypeNameMap.find(sValue); OSL_ENSURE(s_aTypeNameMap.end() != aTypePos, "OXMLDataSourceSetting::OXMLDataSourceSetting: invalid type!"); diff --git a/dbaccess/source/filter/xml/xmlservices.cxx b/dbaccess/source/filter/xml/xmlservices.cxx index 3e52d0ac4fca..5db99d191ab8 100644 --- a/dbaccess/source/filter/xml/xmlservices.cxx +++ b/dbaccess/source/filter/xml/xmlservices.cxx @@ -20,6 +20,7 @@ #include #include #include "xmlservices.hxx" +#include using namespace ::dbaxml; using namespace ::com::sun::star::uno; @@ -30,8 +31,8 @@ extern "C" { static void createRegistryInfo_dbaxml() { - static bool bInit = false; - if (!bInit) + static std::once_flag aInit; + std::call_once(aInit, [&]() { createRegistryInfo_DBTypeDetection(); createRegistryInfo_ODBFilter(); @@ -39,8 +40,8 @@ static void createRegistryInfo_dbaxml() createRegistryInfo_OSettingsExport(); createRegistryInfo_OFullExport(); createRegistryInfo_DBContentLoader2(); - bInit = true; - } + return true; + }); } } diff --git a/dbaccess/source/ui/misc/dsmeta.cxx b/dbaccess/source/ui/misc/dsmeta.cxx index 4d2246bb21c0..82ccab986fd6 100644 --- a/dbaccess/source/ui/misc/dsmeta.cxx +++ b/dbaccess/source/ui/misc/dsmeta.cxx @@ -87,9 +87,9 @@ namespace dbaui static const FeatureSet& lcl_getFeatureSet( const OUString& _rURL ) { typedef std::map< OUString, FeatureSet > FeatureSets; - static FeatureSets s_aFeatureSets; - if ( s_aFeatureSets.empty() ) + static FeatureSets s_aFeatureSets = [&]() { + FeatureSets tmp; ::connectivity::DriversConfig aDriverConfig( ::comphelper::getProcessComponentContext() ); const uno::Sequence< OUString > aPatterns = aDriverConfig.getURLs(); for ( auto const & pattern : aPatterns ) @@ -105,9 +105,10 @@ namespace dbaui ++pFeatureMapping; } - s_aFeatureSets[ pattern ] = aCurrentSet; + tmp[ pattern ] = aCurrentSet; } - } + return tmp; + }(); OSL_ENSURE( s_aFeatureSets.find( _rURL ) != s_aFeatureSets.end(), "invalid URL/pattern!" ); return s_aFeatureSets[ _rURL ]; @@ -115,9 +116,9 @@ namespace dbaui static AuthenticationMode getAuthenticationMode( const OUString& _sURL ) { - static std::map< OUString, FeatureSupport > s_aSupport; - if ( s_aSupport.empty() ) + static std::map< OUString, FeatureSupport > s_aSupport = [&]() { + std::map< OUString, FeatureSupport > tmp; ::connectivity::DriversConfig aDriverConfig(::comphelper::getProcessComponentContext()); const uno::Sequence< OUString > aURLs = aDriverConfig.getURLs(); const OUString* pIter = aURLs.getConstArray(); @@ -135,9 +136,10 @@ namespace dbaui else if ( sAuth == "Password" ) aInit = FeatureSupport(AuthPwd); } - s_aSupport.insert(std::make_pair(*pIter,aInit)); + tmp.insert(std::make_pair(*pIter,aInit)); } - } + return tmp; + }(); OSL_ENSURE(s_aSupport.find(_sURL) != s_aSupport.end(),"Illegal URL!"); return s_aSupport[ _sURL ].eAuthentication; } diff --git a/dbaccess/source/ui/misc/uiservices.cxx b/dbaccess/source/ui/misc/uiservices.cxx index a3d6c8db83e8..c6cdcb2a24f0 100644 --- a/dbaccess/source/ui/misc/uiservices.cxx +++ b/dbaccess/source/ui/misc/uiservices.cxx @@ -20,6 +20,7 @@ #include #include #include +#include using namespace ::dbaui; using namespace ::com::sun::star::uno; @@ -30,8 +31,8 @@ extern "C" { static void createRegistryInfo_DBU() { - static bool bInit = false; - if (!bInit) + static std::once_flag aInit; + std::call_once(aInit, [&]() { createRegistryInfo_OTableFilterDialog(); createRegistryInfo_ODataSourcePropertyDialog(); @@ -57,8 +58,8 @@ static void createRegistryInfo_DBU() createRegistryInfo_CopyTableWizard(); createRegistryInfo_OTextConnectionSettingsDialog(); createRegistryInfo_LimitBoxController(); - bInit = true; - } + return true; + }); } } -- cgit