summaryrefslogtreecommitdiff
path: root/xmloff/source
diff options
context:
space:
mode:
authorNoel Grandin <noelgrandin@gmail.com>2021-07-31 19:03:44 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2021-08-01 13:56:26 +0200
commite698cbd8f860ba6f483f1476e694706717451d2f (patch)
tree831990114bffaf436619285f7ddf356bcbd056af /xmloff/source
parenta32af6867b7fdc6dccf78ffbb63573fd4224883b (diff)
osl::Mutex->static local in EnhancedCustomShapeToken
Change-Id: I436df7f8088c6f5f9376ca9d45d9ce4b7de06069 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/119752 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'xmloff/source')
-rw-r--r--xmloff/source/draw/EnhancedCustomShapeToken.cxx38
1 files changed, 17 insertions, 21 deletions
diff --git a/xmloff/source/draw/EnhancedCustomShapeToken.cxx b/xmloff/source/draw/EnhancedCustomShapeToken.cxx
index 34bc3f61b874..38ca0df48e6a 100644
--- a/xmloff/source/draw/EnhancedCustomShapeToken.cxx
+++ b/xmloff/source/draw/EnhancedCustomShapeToken.cxx
@@ -18,20 +18,12 @@
*/
#include <EnhancedCustomShapeToken.hxx>
-#include <osl/mutex.hxx>
#include <xmloff/xmlimp.hxx>
#include <unordered_map>
#include <memory>
namespace xmloff::EnhancedCustomShapeToken {
-typedef std::unordered_map< const char*, EnhancedCustomShapeTokenEnum, rtl::CStringHash, rtl::CStringEqual> TypeNameHashMap;
-static TypeNameHashMap* pHashMap = nullptr;
-static ::osl::Mutex& getHashMapMutex()
-{
- static osl::Mutex s_aHashMapProtection;
- return s_aHashMapProtection;
-}
namespace {
@@ -172,27 +164,31 @@ const TokenTable pTokenTableArray[] =
{ "NotFound", EAS_NotFound }
};
-EnhancedCustomShapeTokenEnum EASGet( const OUString& rShapeType )
+typedef std::unordered_map< const char*, EnhancedCustomShapeTokenEnum, rtl::CStringHash, rtl::CStringEqual> TypeNameHashMap;
+static const TypeNameHashMap& GetNameHashMap()
{
- if ( !pHashMap )
- { // init hash map
- ::osl::MutexGuard aGuard( getHashMapMutex() );
- if ( !pHashMap )
- {
- TypeNameHashMap* pH = new TypeNameHashMap;
+ static TypeNameHashMap aHashMap = []()
+ { // init hash map
+ TypeNameHashMap res;
for (auto const & pair : pTokenTableArray)
- (*pH)[pair.pS] = pair.pE;
- pHashMap = pH;
- }
- }
+ res[pair.pS] = pair.pE;
+ return res;
+ }();
+
+ return aHashMap;
+}
+
+EnhancedCustomShapeTokenEnum EASGet( const OUString& rShapeType )
+{
EnhancedCustomShapeTokenEnum eRetValue = EAS_NotFound;
int i, nLen = rShapeType.getLength();
std::unique_ptr<char[]> pBuf(new char[ nLen + 1 ]);
for ( i = 0; i < nLen; i++ )
pBuf[ i ] = static_cast<char>(rShapeType[ i ]);
pBuf[ i ] = 0;
- TypeNameHashMap::iterator aHashIter( pHashMap->find( pBuf.get() ) );
- if ( aHashIter != pHashMap->end() )
+ auto& rHashMap = GetNameHashMap();
+ TypeNameHashMap::const_iterator aHashIter( rHashMap.find( pBuf.get() ) );
+ if ( aHashIter != rHashMap.end() )
eRetValue = (*aHashIter).second;
return eRetValue;
}