Changeset 268559 in webkit


Ignore:
Timestamp:
Oct 15, 2020 3:27:21 PM (4 years ago)
Author:
Chris Dumez
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):

Location:
trunk/Source/WebCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r268558 r268559  
     12020-10-15  Chris Dumez  <cdumez@apple.com>
     2
     3        [Cocoa] Simplify logic for caching FFTSetups in FFTFrame
     4        https://bugs.webkit.org/show_bug.cgi?id=217782
     5
     6        Reviewed by Eric Carlson.
     7
     8        Simplify logic for caching FFTSetups in FFTFrame:
     9        - Use a local static (NeverDestroyed) to cache the FFTSetups to avoid
     10          heap allocation and simplify logic a bit.
     11        - Drop FFTFrame::cleanup() since it is dead code.
     12
     13        No new tests, no Web-facing behavior change.
     14
     15        * platform/audio/FFTFrame.h:
     16        * platform/audio/FFTFrameStub.cpp:
     17        * platform/audio/gstreamer/FFTFrameGStreamer.cpp:
     18        * platform/audio/mac/FFTFrameMac.cpp:
     19        (WebCore::FFTFrame::fftSetupForSize):
     20
    1212020-10-15  Chris Dumez  <cdumez@apple.com>
    222
  • trunk/Source/WebCore/platform/audio/FFTFrame.h

    r266492 r268559  
    6363
    6464    static void initialize();
    65     static void cleanup();
    6665    void doFFT(const float* data);
    6766    void doInverseFFT(float* data);
     
    102101    static FFTSetup fftSetupForSize(unsigned fftSize);
    103102
    104     static FFTSetup* fftSetups;
    105 
    106103    FFTSetup m_FFTSetup;
    107104
  • trunk/Source/WebCore/platform/audio/FFTFrameStub.cpp

    r267471 r268559  
    7979}
    8080
    81 void FFTFrame::cleanup()
    82 {
    83     ASSERT_NOT_REACHED();
    84 }
    85 
    8681float* FFTFrame::realData() const
    8782{
  • trunk/Source/WebCore/platform/audio/gstreamer/FFTFrameGStreamer.cpp

    r268026 r268559  
    8888}
    8989
    90 void FFTFrame::cleanup()
    91 {
    92 }
    93 
    9490FFTFrame::~FFTFrame()
    9591{
  • trunk/Source/WebCore/platform/audio/mac/FFTFrameMac.cpp

    r268026 r268559  
    3838
    3939#include "VectorMath.h"
     40#include <wtf/NeverDestroyed.h>
     41#include <wtf/Vector.h>
    4042
    4143namespace WebCore {
    4244
    43 const int kMinFFTPow2Size = 2;
    44 const int kMaxFFTPow2Size = 24;
    45 
    46 FFTSetup* FFTFrame::fftSetups = 0;
     45constexpr unsigned kMinFFTPow2Size = 2;
     46constexpr unsigned kMaxFFTPow2Size = 24;
    4747
    4848// Normal constructor: allocates for a given fftSize
     
    124124FFTSetup FFTFrame::fftSetupForSize(unsigned fftSize)
    125125{
    126     if (!fftSetups) {
    127         fftSetups = (FFTSetup*)fastMalloc(sizeof(FFTSetup) * kMaxFFTPow2Size);
    128         memset(fftSetups, 0, sizeof(FFTSetup) * kMaxFFTPow2Size);
    129     }
     126    static NeverDestroyed<Vector<FFTSetup>> fftSetups(kMaxFFTPow2Size, nullptr);
    130127
    131     int pow2size = static_cast<int>(log2(fftSize));
     128    auto pow2size = static_cast<size_t>(log2(fftSize));
    132129    ASSERT(pow2size < kMaxFFTPow2Size);
    133     if (!fftSetups[pow2size])
    134         fftSetups[pow2size] = vDSP_create_fftsetup(pow2size, FFT_RADIX2);
     130    auto& fftSetup = fftSetups->at(pow2size);
     131    if (!fftSetup)
     132        fftSetup = vDSP_create_fftsetup(pow2size, FFT_RADIX2);
    135133
    136     return fftSetups[pow2size];
     134    return fftSetup;
    137135}
    138136
     
    149147void FFTFrame::initialize()
    150148{
    151 }
    152 
    153 void FFTFrame::cleanup()
    154 {
    155     if (!fftSetups)
    156         return;
    157 
    158     for (int i = 0; i < kMaxFFTPow2Size; ++i) {
    159         if (fftSetups[i])
    160             vDSP_destroy_fftsetup(fftSetups[i]);
    161     }
    162 
    163     fastFree(fftSetups);
    164     fftSetups = 0;
    165149}
    166150
Note: See TracChangeset for help on using the changeset viewer.