[Libreoffice-commits] core.git: chart2/source unotools/source vcl/opengl vcl/source vcl/unx xmloff/source
Libreoffice Gerrit user
logerrit at kemper.freedesktop.org
Fri Nov 23 12:35:53 UTC 2018
chart2/source/controller/dialogs/DialogModel.cxx | 81 +++++++++++------------
unotools/source/config/fltrcfg.cxx | 13 ---
vcl/opengl/win/WinDeviceInfo.cxx | 9 +-
vcl/source/window/window.cxx | 5 -
vcl/unx/gtk/gtksys.cxx | 4 -
xmloff/source/forms/propertyimport.cxx | 13 +--
6 files changed, 53 insertions(+), 72 deletions(-)
New commits:
commit 70894bcdb3912dbe87031da0af9ae5d591275e2a
Author: Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Tue Nov 20 13:09:09 2018 +0200
Commit: Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Fri Nov 23 13:35:25 2018 +0100
improve function local statics
simplify the initialisaion and make them thread-safe i.e. initialise
them using the runtime's local static locking.
Thanks to mike kaganski for pointing out the nice lambda approach that
makes this feasible.
Change-Id: I76391189a6d0a3d7eed2d0d88d28dfa6541eaff7
Reviewed-on: https://gerrit.libreoffice.org/63645
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
diff --git a/chart2/source/controller/dialogs/DialogModel.cxx b/chart2/source/controller/dialogs/DialogModel.cxx
index d38ee3c68cbe..281f66c309f7 100644
--- a/chart2/source/controller/dialogs/DialogModel.cxx
+++ b/chart2/source/controller/dialogs/DialogModel.cxx
@@ -75,28 +75,26 @@ OUString lcl_ConvertRole( const OUString & rRoleString )
OUString aResult( rRoleString );
typedef std::map< OUString, OUString > tTranslationMap;
- static tTranslationMap aTranslationMap;
-
- if( aTranslationMap.empty() )
+ static tTranslationMap aTranslationMap =
{
- aTranslationMap[ "categories" ] = ::chart::SchResId( STR_DATA_ROLE_CATEGORIES );
- aTranslationMap[ "error-bars-x" ] = ::chart::SchResId( STR_DATA_ROLE_X_ERROR );
- aTranslationMap[ "error-bars-x-positive" ] = ::chart::SchResId( STR_DATA_ROLE_X_ERROR_POSITIVE );
- aTranslationMap[ "error-bars-x-negative" ] = ::chart::SchResId( STR_DATA_ROLE_X_ERROR_NEGATIVE );
- aTranslationMap[ "error-bars-y" ] = ::chart::SchResId( STR_DATA_ROLE_Y_ERROR );
- aTranslationMap[ "error-bars-y-positive" ] = ::chart::SchResId( STR_DATA_ROLE_Y_ERROR_POSITIVE );
- aTranslationMap[ "error-bars-y-negative" ] = ::chart::SchResId( STR_DATA_ROLE_Y_ERROR_NEGATIVE );
- aTranslationMap[ "label" ] = ::chart::SchResId( STR_DATA_ROLE_LABEL );
- aTranslationMap[ "values-first" ] = ::chart::SchResId( STR_DATA_ROLE_FIRST );
- aTranslationMap[ "values-last" ] = ::chart::SchResId( STR_DATA_ROLE_LAST );
- aTranslationMap[ "values-max" ] = ::chart::SchResId( STR_DATA_ROLE_MAX );
- aTranslationMap[ "values-min" ] = ::chart::SchResId( STR_DATA_ROLE_MIN );
- aTranslationMap[ "values-x" ] = ::chart::SchResId( STR_DATA_ROLE_X );
- aTranslationMap[ "values-y" ] = ::chart::SchResId( STR_DATA_ROLE_Y );
- aTranslationMap[ "values-size" ] = ::chart::SchResId( STR_DATA_ROLE_SIZE );
- aTranslationMap[ "FillColor" ] = ::chart::SchResId( STR_PROPERTY_ROLE_FILLCOLOR );
- aTranslationMap[ "BorderColor" ] = ::chart::SchResId( STR_PROPERTY_ROLE_BORDERCOLOR );
- }
+ { "categories", ::chart::SchResId( STR_DATA_ROLE_CATEGORIES ) },
+ { "error-bars-x", ::chart::SchResId( STR_DATA_ROLE_X_ERROR ) },
+ { "error-bars-x-positive", ::chart::SchResId( STR_DATA_ROLE_X_ERROR_POSITIVE ) },
+ { "error-bars-x-negative", ::chart::SchResId( STR_DATA_ROLE_X_ERROR_NEGATIVE ) },
+ { "error-bars-y", ::chart::SchResId( STR_DATA_ROLE_Y_ERROR ) },
+ { "error-bars-y-positive", ::chart::SchResId( STR_DATA_ROLE_Y_ERROR_POSITIVE ) },
+ { "error-bars-y-negative", ::chart::SchResId( STR_DATA_ROLE_Y_ERROR_NEGATIVE ) },
+ { "label", ::chart::SchResId( STR_DATA_ROLE_LABEL ) },
+ { "values-first", ::chart::SchResId( STR_DATA_ROLE_FIRST ) },
+ { "values-last", ::chart::SchResId( STR_DATA_ROLE_LAST ) },
+ { "values-max", ::chart::SchResId( STR_DATA_ROLE_MAX ) },
+ { "values-min", ::chart::SchResId( STR_DATA_ROLE_MIN ) },
+ { "values-x", ::chart::SchResId( STR_DATA_ROLE_X ) },
+ { "values-y", ::chart::SchResId( STR_DATA_ROLE_Y ) },
+ { "values-size", ::chart::SchResId( STR_DATA_ROLE_SIZE ) },
+ { "FillColor", ::chart::SchResId( STR_PROPERTY_ROLE_FILLCOLOR ) },
+ { "BorderColor", ::chart::SchResId( STR_PROPERTY_ROLE_BORDERCOLOR ) },
+ };
tTranslationMap::const_iterator aIt( aTranslationMap.find( rRoleString ));
if( aIt != aTranslationMap.end())
@@ -108,26 +106,28 @@ OUString lcl_ConvertRole( const OUString & rRoleString )
typedef std::map< OUString, sal_Int32 > lcl_tRoleIndexMap;
-void lcl_createRoleIndexMap( lcl_tRoleIndexMap & rOutMap )
+lcl_tRoleIndexMap lcl_createRoleIndexMap()
{
- rOutMap.clear();
+ lcl_tRoleIndexMap aMap;
sal_Int32 nIndex = 0;
- rOutMap[ "label" ] = ++nIndex;
- rOutMap[ "categories" ] = ++nIndex;
- rOutMap[ "values-x" ] = ++nIndex;
- rOutMap[ "values-y" ] = ++nIndex;
- rOutMap[ "error-bars-x" ] = ++nIndex;
- rOutMap[ "error-bars-x-positive" ] = ++nIndex;
- rOutMap[ "error-bars-x-negative" ] = ++nIndex;
- rOutMap[ "error-bars-y" ] = ++nIndex;
- rOutMap[ "error-bars-y-positive" ] = ++nIndex;
- rOutMap[ "error-bars-y-negative" ] = ++nIndex;
- rOutMap[ "values-first" ] = ++nIndex;
- rOutMap[ "values-min" ] = ++nIndex;
- rOutMap[ "values-max" ] = ++nIndex;
- rOutMap[ "values-last" ] = ++nIndex;
- rOutMap[ "values-size" ] = ++nIndex;
+ aMap[ "label" ] = ++nIndex;
+ aMap[ "categories" ] = ++nIndex;
+ aMap[ "values-x" ] = ++nIndex;
+ aMap[ "values-y" ] = ++nIndex;
+ aMap[ "error-bars-x" ] = ++nIndex;
+ aMap[ "error-bars-x-positive" ] = ++nIndex;
+ aMap[ "error-bars-x-negative" ] = ++nIndex;
+ aMap[ "error-bars-y" ] = ++nIndex;
+ aMap[ "error-bars-y-positive" ] = ++nIndex;
+ aMap[ "error-bars-y-negative" ] = ++nIndex;
+ aMap[ "values-first" ] = ++nIndex;
+ aMap[ "values-min" ] = ++nIndex;
+ aMap[ "values-max" ] = ++nIndex;
+ aMap[ "values-last" ] = ++nIndex;
+ aMap[ "values-size" ] = ++nIndex;
+
+ return aMap;
}
struct lcl_DataSeriesContainerAppend
@@ -766,10 +766,7 @@ OUString DialogModel::GetRoleDataLabel()
sal_Int32 DialogModel::GetRoleIndexForSorting( const OUString & rInternalRoleString )
{
- static lcl_tRoleIndexMap aRoleIndexMap;
-
- if( aRoleIndexMap.empty())
- lcl_createRoleIndexMap( aRoleIndexMap );
+ static lcl_tRoleIndexMap aRoleIndexMap = lcl_createRoleIndexMap();
lcl_tRoleIndexMap::const_iterator aIt( aRoleIndexMap.find( rInternalRoleString ));
if( aIt != aRoleIndexMap.end())
diff --git a/unotools/source/config/fltrcfg.cxx b/unotools/source/config/fltrcfg.cxx
index 32a61fdae8a1..89b8374a761d 100644
--- a/unotools/source/config/fltrcfg.cxx
+++ b/unotools/source/config/fltrcfg.cxx
@@ -303,13 +303,8 @@ namespace {
const Sequence<OUString>& GetPropertyNames()
{
- static Sequence<OUString> aNames;
- if(!aNames.getLength())
+ static Sequence<OUString> const aNames
{
- int nCount = 14;
- aNames.realloc(nCount);
- static const char* aPropNames[] =
- {
"Import/MathTypeToMath", // 0
"Import/WinWordToWriter", // 1
"Import/PowerPointToImpress", // 2
@@ -324,11 +319,7 @@ const Sequence<OUString>& GetPropertyNames()
"Import/ImportWWFieldsAsEnhancedFields", // 11
"Import/SmartArtToShapes", // 12
"Export/CharBackgroundToHighlighting" // 13
- };
- OUString* pNames = aNames.getArray();
- for(int i = 0; i < nCount; i++)
- pNames[i] = OUString::createFromAscii(aPropNames[i]);
- }
+ };
return aNames;
}
diff --git a/vcl/opengl/win/WinDeviceInfo.cxx b/vcl/opengl/win/WinDeviceInfo.cxx
index 9c48651918a5..2ebccf9ee6f4 100644
--- a/vcl/opengl/win/WinDeviceInfo.cxx
+++ b/vcl/opengl/win/WinDeviceInfo.cxx
@@ -190,9 +190,7 @@ wgl::OperatingSystem WindowsVersionToOperatingSystem(int32_t aWindowsVersion)
int32_t WindowsOSVersion()
{
- static int32_t winVersion = kWindowsUnknown;
-
- if (winVersion == kWindowsUnknown)
+ static int32_t winVersion = [&]()
{
// GetVersion(Ex) and VersionHelpers (based on VerifyVersionInfo) API are
// subject to manifest-based behavior since Windows 8.1, so give wrong results.
@@ -219,13 +217,14 @@ int32_t WindowsOSVersion()
if (VerQueryValueW(ver.get(), L"\\", &pBlock, &dwBlockSz) != FALSE && dwBlockSz >= sizeof(VS_FIXEDFILEINFO))
{
VS_FIXEDFILEINFO *vinfo = static_cast<VS_FIXEDFILEINFO *>(pBlock);
- winVersion = int32_t(vinfo->dwProductVersionMS);
+ return int32_t(vinfo->dwProductVersionMS);
}
}
}
}
}
- }
+ return int32_t(kWindowsUnknown);
+ }();
return winVersion;
}
diff --git a/vcl/source/window/window.cxx b/vcl/source/window/window.cxx
index 9212e55bef1a..e1d97513172d 100644
--- a/vcl/source/window/window.cxx
+++ b/vcl/source/window/window.cxx
@@ -3167,10 +3167,7 @@ LOKWindowsMap& GetLOKWindowsMap()
assert(comphelper::LibreOfficeKit::isActive());
// Map to remember the LOKWindowId <-> Window binding.
- static std::unique_ptr<LOKWindowsMap> s_pLOKWindowsMap;
-
- if (!s_pLOKWindowsMap)
- s_pLOKWindowsMap.reset(new LOKWindowsMap);
+ static std::unique_ptr<LOKWindowsMap> s_pLOKWindowsMap(new LOKWindowsMap);
return *s_pLOKWindowsMap;
}
diff --git a/vcl/unx/gtk/gtksys.cxx b/vcl/unx/gtk/gtksys.cxx
index d99d294301a0..bad2285576d5 100644
--- a/vcl/unx/gtk/gtksys.cxx
+++ b/vcl/unx/gtk/gtksys.cxx
@@ -25,9 +25,7 @@
GtkSalSystem *GtkSalSystem::GetSingleton()
{
- static GtkSalSystem *pSingleton = nullptr;
- if (!pSingleton)
- pSingleton = new GtkSalSystem();
+ static GtkSalSystem *pSingleton = new GtkSalSystem();
return pSingleton;
}
diff --git a/xmloff/source/forms/propertyimport.cxx b/xmloff/source/forms/propertyimport.cxx
index 540d670c8a0c..e9ac0bba5dec 100644
--- a/xmloff/source/forms/propertyimport.cxx
+++ b/xmloff/source/forms/propertyimport.cxx
@@ -233,19 +233,18 @@ Type PropertyConversion::xmlTypeToUnoType( const OUString& _rType )
{
Type aUnoType( cppu::UnoType<void>::get() );
- static std::map< OUString, css::uno::Type > s_aTypeNameMap;
- if ( s_aTypeNameMap.empty() )
+ static std::map< OUString, css::uno::Type > s_aTypeNameMap
{
- s_aTypeNameMap[ token::GetXMLToken( token::XML_BOOLEAN ) ] = cppu::UnoType<bool>::get();
+ { token::GetXMLToken( token::XML_BOOLEAN ) , cppu::UnoType<bool>::get()},
// Not a copy paste error, quotation from:
// http://nabble.documentfoundation.org/Question-unoType-for-getXmlToken-dbaccess-reportdesign-module-tp4109071p4109116.html
// all numeric types (including the UNO double)
// consistently map to XML_FLOAT, so taking the extra precision from the
// C++ type "float" to "double" makes absolute sense
- s_aTypeNameMap[ token::GetXMLToken( token::XML_FLOAT ) ] = ::cppu::UnoType<double>::get();
- s_aTypeNameMap[ token::GetXMLToken( token::XML_STRING ) ] = ::cppu::UnoType<OUString>::get();
- s_aTypeNameMap[ token::GetXMLToken( token::XML_VOID ) ] = cppu::UnoType<void>::get();
- }
+ { token::GetXMLToken( token::XML_FLOAT ) , ::cppu::UnoType<double>::get()},
+ { token::GetXMLToken( token::XML_STRING ) , ::cppu::UnoType<OUString>::get()},
+ { token::GetXMLToken( token::XML_VOID ) , cppu::UnoType<void>::get() },
+ };
const std::map< OUString, css::uno::Type >::iterator aTypePos = s_aTypeNameMap.find( _rType );
OSL_ENSURE( s_aTypeNameMap.end() != aTypePos, "PropertyConversion::xmlTypeToUnoType: invalid property name!" );
More information about the Libreoffice-commits
mailing list