diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-11-21 11:47:47 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-11-22 07:33:56 +0100 |
commit | 2e6a38b7f007b36719f5fc002cb4363dec45e0d4 (patch) | |
tree | 7b9c691228821149d96d3859be07f50bc1e93515 /dbaccess | |
parent | ca037ca06e5b261a243af15aa57d2b8ee047806e (diff) |
improve function-local statics in dbaccess..filter
Change-Id: I64939ad4b6c53696e33300114db384abfe73f13f
Reviewed-on: https://gerrit.libreoffice.org/63702
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'dbaccess')
-rw-r--r-- | dbaccess/source/filter/xml/xmlDataSourceSetting.cxx | 21 | ||||
-rw-r--r-- | dbaccess/source/filter/xml/xmlservices.cxx | 9 | ||||
-rw-r--r-- | dbaccess/source/ui/misc/dsmeta.cxx | 18 | ||||
-rw-r--r-- | dbaccess/source/ui/misc/uiservices.cxx | 9 |
4 files changed, 31 insertions, 26 deletions
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<bool>::get(); + std::map< OUString, css::uno::Type > tmp; + tmp[GetXMLToken( XML_BOOLEAN)] = cppu::UnoType<bool>::get(); // Not a copy paste error, see comment xmloff/source/forms/propertyimport.cxx lines 244-248 - s_aTypeNameMap[GetXMLToken( XML_FLOAT)] = ::cppu::UnoType<double>::get(); - s_aTypeNameMap[GetXMLToken( XML_DOUBLE)] = ::cppu::UnoType<double>::get(); - s_aTypeNameMap[GetXMLToken( XML_STRING)] = ::cppu::UnoType<OUString>::get(); - s_aTypeNameMap[GetXMLToken( XML_INT)] = ::cppu::UnoType<sal_Int32>::get(); - s_aTypeNameMap[GetXMLToken( XML_SHORT)] = ::cppu::UnoType<sal_Int16>::get(); - s_aTypeNameMap[GetXMLToken( XML_VOID)] = cppu::UnoType<void>::get(); - } + tmp[GetXMLToken( XML_FLOAT)] = ::cppu::UnoType<double>::get(); + tmp[GetXMLToken( XML_DOUBLE)] = ::cppu::UnoType<double>::get(); + tmp[GetXMLToken( XML_STRING)] = ::cppu::UnoType<OUString>::get(); + tmp[GetXMLToken( XML_INT)] = ::cppu::UnoType<sal_Int32>::get(); + tmp[GetXMLToken( XML_SHORT)] = ::cppu::UnoType<sal_Int16>::get(); + tmp[GetXMLToken( XML_VOID)] = cppu::UnoType<void>::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 <cppuhelper/factory.hxx> #include <flt_reghelper.hxx> #include "xmlservices.hxx" +#include <mutex> 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 <cppuhelper/factory.hxx> #include <dbu_reghelper.hxx> #include <uiservices.hxx> +#include <mutex> 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; + }); } } |