[Libreoffice-commits] core.git: xmloff/source

Noel Grandin (via logerrit) logerrit at kemper.freedesktop.org
Sun Aug 1 12:01:21 UTC 2021


 xmloff/source/draw/EnhancedCustomShapeToken.cxx |   38 ++++++++++--------------
 1 file changed, 17 insertions(+), 21 deletions(-)

New commits:
commit e698cbd8f860ba6f483f1476e694706717451d2f
Author:     Noel Grandin <noelgrandin at gmail.com>
AuthorDate: Sat Jul 31 19:03:44 2021 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Sun Aug 1 13:56:26 2021 +0200

    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 at collabora.co.uk>

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;
 }


More information about the Libreoffice-commits mailing list