Simplify HRTFDatabaseLoader's load map
authorzandobersek@gmail.com <zandobersek@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 22 Oct 2013 20:10:52 +0000 (20:10 +0000)
committerzandobersek@gmail.com <zandobersek@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 22 Oct 2013 20:10:52 +0000 (20:10 +0000)
https://bugs.webkit.org/show_bug.cgi?id=122944

Reviewed by Eric Carlson.

* platform/audio/HRTFDatabaseLoader.cpp:
(WebCore::loaderMap): Return a reference to a NeverDestroyed HashMap that maps sample rates to loaders.
(WebCore::HRTFDatabaseLoader::createAndLoadAsynchronouslyIfNecessary):
(WebCore::HRTFDatabaseLoader::~HRTFDatabaseLoader):
* platform/audio/HRTFDatabaseLoader.h: Remove the LoaderMap type definition, the private singleton of that type
and the singleton's unused getter.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@157806 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/platform/audio/HRTFDatabaseLoader.cpp
Source/WebCore/platform/audio/HRTFDatabaseLoader.h

index cf98980..641e2f2 100644 (file)
@@ -1,3 +1,17 @@
+2013-10-22  Zan Dobersek  <zdobersek@igalia.com>
+
+        Simplify HRTFDatabaseLoader's load map
+        https://bugs.webkit.org/show_bug.cgi?id=122944
+
+        Reviewed by Eric Carlson.
+
+        * platform/audio/HRTFDatabaseLoader.cpp:
+        (WebCore::loaderMap): Return a reference to a NeverDestroyed HashMap that maps sample rates to loaders.
+        (WebCore::HRTFDatabaseLoader::createAndLoadAsynchronouslyIfNecessary):
+        (WebCore::HRTFDatabaseLoader::~HRTFDatabaseLoader):
+        * platform/audio/HRTFDatabaseLoader.h: Remove the LoaderMap type definition, the private singleton of that type
+        and the singleton's unused getter.
+
 2013-10-22  Tim Horton  <timothy_horton@apple.com>
 
         Remote Layer Tree: Support hardware accelerated filters
index 6160f66..5555e91 100644 (file)
 
 #include "HRTFDatabase.h"
 #include <wtf/MainThread.h>
+#include <wtf/NeverDestroyed.h>
 
 namespace WebCore {
 
-// Singleton
-HRTFDatabaseLoader::LoaderMap* HRTFDatabaseLoader::s_loaderMap = 0;
+// Keeps track of loaders on a per-sample-rate basis.
+static HashMap<double, HRTFDatabaseLoader*>& loaderMap()
+{
+    static NeverDestroyed<HashMap<double, HRTFDatabaseLoader*>> loaderMap;
+    return loaderMap;
+}
 
 PassRefPtr<HRTFDatabaseLoader> HRTFDatabaseLoader::createAndLoadAsynchronouslyIfNecessary(float sampleRate)
 {
@@ -46,17 +51,14 @@ PassRefPtr<HRTFDatabaseLoader> HRTFDatabaseLoader::createAndLoadAsynchronouslyIf
 
     RefPtr<HRTFDatabaseLoader> loader;
     
-    if (!s_loaderMap)
-        s_loaderMap = adoptPtr(new LoaderMap()).leakPtr();
-
-    loader = s_loaderMap->get(sampleRate);
+    loader = loaderMap().get(sampleRate);
     if (loader) {
         ASSERT(sampleRate == loader->databaseSampleRate());
         return loader;
     }
 
     loader = adoptRef(new HRTFDatabaseLoader(sampleRate));
-    s_loaderMap->add(sampleRate, loader.get());
+    loaderMap().add(sampleRate, loader.get());
 
     loader->loadAsynchronously();
 
@@ -78,8 +80,7 @@ HRTFDatabaseLoader::~HRTFDatabaseLoader()
     m_hrtfDatabase.clear();
 
     // Remove ourself from the map.
-    if (s_loaderMap)
-        s_loaderMap->remove(m_databaseSampleRate);
+    loaderMap().remove(m_databaseSampleRate);
 }
 
 // Asynchronously load the database in this thread.
index 8c2f53f..dd98e55 100644 (file)
@@ -72,13 +72,6 @@ private:
     // This must be called from the main thread.
     void loadAsynchronously();
 
-    // Map from sample-rate to loader.
-    typedef HashMap<double, HRTFDatabaseLoader*> LoaderMap;
-
-    // Keeps track of loaders on a per-sample-rate basis.
-    static LoaderMap* s_loaderMap; // singleton
-    static HRTFDatabaseLoader::LoaderMap* loaderMap() { return s_loaderMap; }
-
     OwnPtr<HRTFDatabase> m_hrtfDatabase;
 
     // Holding a m_threadLock is required when accessing m_databaseLoaderThread.