Title: [268559] trunk/Source/WebCore
Revision
268559
Author
[email protected]
Date
2020-10-15 15:27:21 -0700 (Thu, 15 Oct 2020)

Log Message

[Cocoa] Simplify logic for caching FFTSetups in FFTFrame
https://bugs.webkit.org/show_bug.cgi?id=217782

Reviewed by Eric Carlson.

Simplify logic for caching FFTSetups in FFTFrame:
- Use a local static (NeverDestroyed) to cache the FFTSetups to avoid
  heap allocation and simplify logic a bit.
- Drop FFTFrame::cleanup() since it is dead code.

No new tests, no Web-facing behavior change.

* platform/audio/FFTFrame.h:
* platform/audio/FFTFrameStub.cpp:
* platform/audio/gstreamer/FFTFrameGStreamer.cpp:
* platform/audio/mac/FFTFrameMac.cpp:
(WebCore::FFTFrame::fftSetupForSize):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (268558 => 268559)


--- trunk/Source/WebCore/ChangeLog	2020-10-15 22:24:27 UTC (rev 268558)
+++ trunk/Source/WebCore/ChangeLog	2020-10-15 22:27:21 UTC (rev 268559)
@@ -1,5 +1,25 @@
 2020-10-15  Chris Dumez  <[email protected]>
 
+        [Cocoa] Simplify logic for caching FFTSetups in FFTFrame
+        https://bugs.webkit.org/show_bug.cgi?id=217782
+
+        Reviewed by Eric Carlson.
+
+        Simplify logic for caching FFTSetups in FFTFrame:
+        - Use a local static (NeverDestroyed) to cache the FFTSetups to avoid
+          heap allocation and simplify logic a bit.
+        - Drop FFTFrame::cleanup() since it is dead code.
+
+        No new tests, no Web-facing behavior change.
+
+        * platform/audio/FFTFrame.h:
+        * platform/audio/FFTFrameStub.cpp:
+        * platform/audio/gstreamer/FFTFrameGStreamer.cpp:
+        * platform/audio/mac/FFTFrameMac.cpp:
+        (WebCore::FFTFrame::fftSetupForSize):
+
+2020-10-15  Chris Dumez  <[email protected]>
+
         Use std::fill_n() instead of for loops in ConstantSourceNode
         https://bugs.webkit.org/show_bug.cgi?id=217777
 

Modified: trunk/Source/WebCore/platform/audio/FFTFrame.h (268558 => 268559)


--- trunk/Source/WebCore/platform/audio/FFTFrame.h	2020-10-15 22:24:27 UTC (rev 268558)
+++ trunk/Source/WebCore/platform/audio/FFTFrame.h	2020-10-15 22:27:21 UTC (rev 268559)
@@ -62,7 +62,6 @@
     ~FFTFrame();
 
     static void initialize();
-    static void cleanup();
     void doFFT(const float* data);
     void doInverseFFT(float* data);
     void multiply(const FFTFrame& frame); // multiplies ourself with frame : effectively operator*=()
@@ -101,8 +100,6 @@
 
     static FFTSetup fftSetupForSize(unsigned fftSize);
 
-    static FFTSetup* fftSetups;
-
     FFTSetup m_FFTSetup;
 
     DSPSplitComplex m_frame;

Modified: trunk/Source/WebCore/platform/audio/FFTFrameStub.cpp (268558 => 268559)


--- trunk/Source/WebCore/platform/audio/FFTFrameStub.cpp	2020-10-15 22:24:27 UTC (rev 268558)
+++ trunk/Source/WebCore/platform/audio/FFTFrameStub.cpp	2020-10-15 22:27:21 UTC (rev 268559)
@@ -78,11 +78,6 @@
 {
 }
 
-void FFTFrame::cleanup()
-{
-    ASSERT_NOT_REACHED();
-}
-
 float* FFTFrame::realData() const
 {
     ASSERT_NOT_REACHED();

Modified: trunk/Source/WebCore/platform/audio/gstreamer/FFTFrameGStreamer.cpp (268558 => 268559)


--- trunk/Source/WebCore/platform/audio/gstreamer/FFTFrameGStreamer.cpp	2020-10-15 22:24:27 UTC (rev 268558)
+++ trunk/Source/WebCore/platform/audio/gstreamer/FFTFrameGStreamer.cpp	2020-10-15 22:27:21 UTC (rev 268559)
@@ -87,10 +87,6 @@
 {
 }
 
-void FFTFrame::cleanup()
-{
-}
-
 FFTFrame::~FFTFrame()
 {
     if (!m_fft)

Modified: trunk/Source/WebCore/platform/audio/mac/FFTFrameMac.cpp (268558 => 268559)


--- trunk/Source/WebCore/platform/audio/mac/FFTFrameMac.cpp	2020-10-15 22:24:27 UTC (rev 268558)
+++ trunk/Source/WebCore/platform/audio/mac/FFTFrameMac.cpp	2020-10-15 22:27:21 UTC (rev 268559)
@@ -37,14 +37,14 @@
 #include "FFTFrame.h"
 
 #include "VectorMath.h"
+#include <wtf/NeverDestroyed.h>
+#include <wtf/Vector.h>
 
 namespace WebCore {
 
-const int kMinFFTPow2Size = 2;
-const int kMaxFFTPow2Size = 24;
+constexpr unsigned kMinFFTPow2Size = 2;
+constexpr unsigned kMaxFFTPow2Size = 24;
 
-FFTSetup* FFTFrame::fftSetups = 0;
-
 // Normal constructor: allocates for a given fftSize
 FFTFrame::FFTFrame(unsigned fftSize)
     : m_realData(fftSize)
@@ -123,17 +123,15 @@
 
 FFTSetup FFTFrame::fftSetupForSize(unsigned fftSize)
 {
-    if (!fftSetups) {
-        fftSetups = (FFTSetup*)fastMalloc(sizeof(FFTSetup) * kMaxFFTPow2Size);
-        memset(fftSetups, 0, sizeof(FFTSetup) * kMaxFFTPow2Size);
-    }
+    static NeverDestroyed<Vector<FFTSetup>> fftSetups(kMaxFFTPow2Size, nullptr);
 
-    int pow2size = static_cast<int>(log2(fftSize));
+    auto pow2size = static_cast<size_t>(log2(fftSize));
     ASSERT(pow2size < kMaxFFTPow2Size);
-    if (!fftSetups[pow2size])
-        fftSetups[pow2size] = vDSP_create_fftsetup(pow2size, FFT_RADIX2);
+    auto& fftSetup = fftSetups->at(pow2size);
+    if (!fftSetup)
+        fftSetup = vDSP_create_fftsetup(pow2size, FFT_RADIX2);
 
-    return fftSetups[pow2size];
+    return fftSetup;
 }
 
 int FFTFrame::minFFTSize()
@@ -150,20 +148,6 @@
 {
 }
 
-void FFTFrame::cleanup()
-{
-    if (!fftSetups)
-        return;
-
-    for (int i = 0; i < kMaxFFTPow2Size; ++i) {
-        if (fftSetups[i])
-            vDSP_destroy_fftsetup(fftSetups[i]);
-    }
-
-    fastFree(fftSetups);
-    fftSetups = 0;
-}
-
 float* FFTFrame::realData() const
 {
     return m_frame.realp;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to