summaryrefslogtreecommitdiffstats
path: root/oox
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2018-11-04 20:31:58 +0300
committerMike Kaganski <mike.kaganski@collabora.com>2018-11-05 13:26:36 +0100
commite07253e0262a11dc96a98598c55c43da16b9678a (patch)
tree5e803be171a4ec248ed5053258e3ea9d0a0f0e81 /oox
parenttdf#118573: Acquire solar mutex when calling Application::Reschedule (diff)
downloadcore-e07253e0262a11dc96a98598c55c43da16b9678a.tar.gz
core-e07253e0262a11dc96a98598c55c43da16b9678a.zip
replace double-checked locking patterns with thread safe local statics
Change-Id: I4ed97cc6d9f733292156d71551d5ce3af6071445 Reviewed-on: https://gerrit.libreoffice.org/62858 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'oox')
-rw-r--r--oox/source/drawingml/presetgeometrynames.cxx30
1 files changed, 8 insertions, 22 deletions
diff --git a/oox/source/drawingml/presetgeometrynames.cxx b/oox/source/drawingml/presetgeometrynames.cxx
index 4939cfcf0a3f..272094dd7ef6 100644
--- a/oox/source/drawingml/presetgeometrynames.cxx
+++ b/oox/source/drawingml/presetgeometrynames.cxx
@@ -20,13 +20,6 @@ namespace
typedef std::unordered_map<const char*, const char*, rtl::CStringHash, rtl::CStringEqual>
PresetGeometryHashMap;
-static PresetGeometryHashMap* pHashMap = nullptr;
-::osl::Mutex& getHashMapMutex()
-{
- static osl::Mutex s_aHashMapProtection;
- return s_aHashMapProtection;
-}
-
struct PresetGeometryName
{
const char* pMsoName;
@@ -79,27 +72,20 @@ static const PresetGeometryName pPresetGeometryNameArray[]
OUString PresetGeometryTypeNames::GetFontworkType(const OUString& rMsoType)
{
- if (!pHashMap)
- { // init hash map
- ::osl::MutexGuard aGuard(getHashMapMutex());
- if (!pHashMap)
- {
- PresetGeometryHashMap* pH = new PresetGeometryHashMap;
- const PresetGeometryName* pPtr = pPresetGeometryNameArray;
- const PresetGeometryName* pEnd = pPtr + SAL_N_ELEMENTS(pPresetGeometryNameArray);
- for (; pPtr < pEnd; pPtr++)
- (*pH)[pPtr->pMsoName] = pPtr->pFontworkType;
- pHashMap = pH;
- }
- }
+ static const PresetGeometryHashMap s_HashMap = []() {
+ PresetGeometryHashMap aH;
+ for (const auto& item : pPresetGeometryNameArray)
+ aH[item.pMsoName] = item.pFontworkType;
+ return aH;
+ }();
const char* pRetValue = "";
int i, nLen = rMsoType.getLength();
std::unique_ptr<char[]> pBuf(new char[nLen + 1]);
for (i = 0; i < nLen; i++)
pBuf[i] = static_cast<char>(rMsoType[i]);
pBuf[i] = 0;
- PresetGeometryHashMap::const_iterator aHashIter(pHashMap->find(pBuf.get()));
- if (aHashIter != pHashMap->end())
+ PresetGeometryHashMap::const_iterator aHashIter(s_HashMap.find(pBuf.get()));
+ if (aHashIter != s_HashMap.end())
pRetValue = (*aHashIter).second;
return OUString(pRetValue, strlen(pRetValue), RTL_TEXTENCODING_ASCII_US);