bug 1172979 use AutoTArray for AudioChunk::mChannelData to reduce allocations r?padenot draft
authorKarl Tomlinson <karlt+@karlt.net>
Fri, 11 Aug 2017 11:54:36 +1200
changeset 646086 d9fe421dd0d2b4d234beb685086761df62d5c539
parent 646085 5a78dea62dc52ca52fc207f98383b4a0cd57b6a8
child 726134 d58ffb3def516adbd7e9e9601fd33e96218b6ffe
push id74001
push userktomlinson@mozilla.com
push dateMon, 14 Aug 2017 21:14:48 +0000
reviewerspadenot
bugs1172979
milestone57.0a1
bug 1172979 use AutoTArray for AudioChunk::mChannelData to reduce allocations r?padenot MozReview-Commit-ID: wabk0WlLv5
dom/media/AudioSegment.h
dom/media/webaudio/AudioBlock.h
--- a/dom/media/AudioSegment.h
+++ b/dom/media/AudioSegment.h
@@ -12,16 +12,21 @@
 #include "SharedBuffer.h"
 #include "WebAudioUtils.h"
 #ifdef MOZILLA_INTERNAL_API
 #include "mozilla/TimeStamp.h"
 #endif
 #include <float.h>
 
 namespace mozilla {
+  struct AudioChunk;
+}
+DECLARE_USE_COPY_CONSTRUCTORS(mozilla::AudioChunk)
+
+namespace mozilla {
 
 template<typename T>
 class SharedChannelArrayBuffer : public ThreadSharedObject {
 public:
   explicit SharedChannelArrayBuffer(nsTArray<nsTArray<T> >* aBuffers)
   {
     mBuffers.SwapElements(*aBuffers);
   }
@@ -219,24 +224,26 @@ struct AudioChunk {
     amount += mChannelData.ShallowSizeOfExcludingThis(aMallocSizeOf);
     return amount;
   }
 
   template<typename T>
   const nsTArray<const T*>& ChannelData() const
   {
     MOZ_ASSERT(AudioSampleTypeToFormat<T>::Format == mBufferFormat);
-    return *reinterpret_cast<const nsTArray<const T*>*>(&mChannelData);
+    return *reinterpret_cast<const AutoTArray<const T*,GUESS_AUDIO_CHANNELS>*>
+      (&mChannelData);
   }
 
   PrincipalHandle GetPrincipalHandle() const { return mPrincipalHandle; }
 
   StreamTime mDuration; // in frames within the buffer
   RefPtr<ThreadSharedObject> mBuffer; // the buffer object whose lifetime is managed; null means data is all zeroes
-  nsTArray<const void*> mChannelData; // one pointer per channel; empty if and only if mBuffer is null
+  // one pointer per channel; empty if and only if mBuffer is null
+  AutoTArray<const void*,GUESS_AUDIO_CHANNELS> mChannelData;
   float mVolume; // volume multiplier to apply (1.0f if mBuffer is nonnull)
   SampleFormat mBufferFormat; // format of frames in mBuffer (only meaningful if mBuffer is nonnull)
 #ifdef MOZILLA_INTERNAL_API
   mozilla::TimeStamp mTimeStamp;           // time at which this has been fetched from the MediaEngine
 #endif
   // principalHandle for the data in this chunk.
   // This can be compared to an nsIPrincipal* when back on main thread.
   PrincipalHandle mPrincipalHandle;
--- a/dom/media/webaudio/AudioBlock.h
+++ b/dom/media/webaudio/AudioBlock.h
@@ -128,9 +128,11 @@ private:
   // reference does not prevent the upstream node from re-using the buffer next
   // iteration and modifying its contents.  The AudioBlockBuffer is also
   // notified when mBuffer releases this reference.
   bool mBufferIsDownstreamRef = false;
 };
 
 } // namespace mozilla
 
+DECLARE_USE_COPY_CONSTRUCTORS(mozilla::AudioBlock)
+
 #endif // MOZILLA_AUDIOBLOCK_H_