Title: [157806] trunk/Source/WebCore
Revision
157806
Author
zandober...@gmail.com
Date
2013-10-22 13:10:52 -0700 (Tue, 22 Oct 2013)

Log Message

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.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (157805 => 157806)


--- trunk/Source/WebCore/ChangeLog	2013-10-22 19:46:15 UTC (rev 157805)
+++ trunk/Source/WebCore/ChangeLog	2013-10-22 20:10:52 UTC (rev 157806)
@@ -1,3 +1,17 @@
+2013-10-22  Zan Dobersek  <zdober...@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_hor...@apple.com>
 
         Remote Layer Tree: Support hardware accelerated filters

Modified: trunk/Source/WebCore/platform/audio/HRTFDatabaseLoader.cpp (157805 => 157806)


--- trunk/Source/WebCore/platform/audio/HRTFDatabaseLoader.cpp	2013-10-22 19:46:15 UTC (rev 157805)
+++ trunk/Source/WebCore/platform/audio/HRTFDatabaseLoader.cpp	2013-10-22 20:10:52 UTC (rev 157806)
@@ -34,11 +34,16 @@
 
 #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 @@
 
     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 @@
     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.

Modified: trunk/Source/WebCore/platform/audio/HRTFDatabaseLoader.h (157805 => 157806)


--- trunk/Source/WebCore/platform/audio/HRTFDatabaseLoader.h	2013-10-22 19:46:15 UTC (rev 157805)
+++ trunk/Source/WebCore/platform/audio/HRTFDatabaseLoader.h	2013-10-22 20:10:52 UTC (rev 157806)
@@ -72,13 +72,6 @@
     // 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.
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to