Bug 1317430 - Avoid a unnecessary copy by passing a const & in dom/media/ draft
authorSylvestre Ledru <sledru@mozilla.com>
Mon, 14 Nov 2016 23:15:53 +0100
changeset 438671 8c8d67d23f62930d13080bbf4d32cc684a6f4d09
parent 438670 237bcd276f38a2b33bfe9de31769b73fb9025a4b
child 438672 8b933ad0315c457edc4d36cb8595806c7fc8b762
push id35794
push usersledru@mozilla.com
push dateMon, 14 Nov 2016 22:18:09 +0000
bugs1317430
milestone52.0a1
Bug 1317430 - Avoid a unnecessary copy by passing a const & in dom/media/ MozReview-Commit-ID: 9MDVY9mgui0
dom/media/MediaFormatReader.h
dom/media/MediaSegment.h
dom/media/VideoUtils.h
dom/media/gmp/widevine-adapter/WidevineDecryptor.cpp
--- a/dom/media/MediaFormatReader.h
+++ b/dom/media/MediaFormatReader.h
@@ -2,16 +2,18 @@
 /* vim:set ts=2 sw=2 sts=2 et cindent: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #if !defined(MediaFormatReader_h_)
 #define MediaFormatReader_h_
 
+#include <utility>
+
 #include "mozilla/Atomics.h"
 #include "mozilla/Maybe.h"
 #include "mozilla/TaskQueue.h"
 #include "mozilla/Monitor.h"
 
 #include "MediaEventSource.h"
 #include "MediaDataDemuxer.h"
 #include "MediaDecoderReader.h"
@@ -564,17 +566,17 @@ private:
   void OnSeekFailed(TrackType aTrack, const MediaResult& aError);
   void DoVideoSeek();
   void OnVideoSeekCompleted(media::TimeUnit aTime);
   void OnVideoSeekFailed(const MediaResult& aError);
   bool mSeekScheduled;
 
   void NotifyCompositorUpdated(RefPtr<layers::KnowsCompositor> aKnowsCompositor)
   {
-    mKnowsCompositor = aKnowsCompositor;
+    mKnowsCompositor = std::move(aKnowsCompositor);
   }
 
   void DoAudioSeek();
   void OnAudioSeekCompleted(media::TimeUnit aTime);
   void OnAudioSeekFailed(const MediaResult& aError);
   // The SeekTarget that was last given to Seek()
   SeekTarget mOriginalSeekTarget;
   // Temporary seek information while we wait for the data
--- a/dom/media/MediaSegment.h
+++ b/dom/media/MediaSegment.h
@@ -134,17 +134,17 @@ public:
   /**
    * Gets the last principal id that was appended to this segment.
    */
   PrincipalHandle GetLastPrincipalHandle() const { return mLastPrincipalHandle; }
   /**
    * Called by the MediaStreamGraph as it appends a chunk with a different
    * principal id than the current one.
    */
-  void SetLastPrincipalHandle(PrincipalHandle aLastPrincipalHandle)
+  void SetLastPrincipalHandle(const PrincipalHandle& aLastPrincipalHandle)
   {
     mLastPrincipalHandle = aLastPrincipalHandle;
   }
 
   /**
    * Create a MediaSegment of the same type.
    */
   virtual MediaSegment* CreateEmptyClone() const = 0;
--- a/dom/media/VideoUtils.h
+++ b/dom/media/VideoUtils.h
@@ -283,17 +283,17 @@ template<class Work, class Condition>
 RefPtr<GenericPromise> InvokeUntil(Work aWork, Condition aCondition) {
   RefPtr<GenericPromise::Private> p = new GenericPromise::Private(__func__);
 
   if (aCondition()) {
     p->Resolve(true, __func__);
   }
 
   struct Helper {
-    static void Iteration(RefPtr<GenericPromise::Private> aPromise, Work aLocalWork, Condition aLocalCondition) {
+    static void Iteration(const RefPtr<GenericPromise::Private>& aPromise, Work aLocalWork, Condition aLocalCondition) {
       if (!aLocalWork()) {
         aPromise->Reject(NS_ERROR_FAILURE, __func__);
       } else if (aLocalCondition()) {
         aPromise->Resolve(true, __func__);
       } else {
         nsCOMPtr<nsIRunnable> r =
           NS_NewRunnableFunction([aPromise, aLocalWork, aLocalCondition] () { Iteration(aPromise, aLocalWork, aLocalCondition); });
         AbstractThread::GetCurrent()->Dispatch(r.forget());
--- a/dom/media/gmp/widevine-adapter/WidevineDecryptor.cpp
+++ b/dom/media/gmp/widevine-adapter/WidevineDecryptor.cpp
@@ -6,16 +6,18 @@
 #include "WidevineDecryptor.h"
 
 #include "WidevineAdapter.h"
 #include "WidevineUtils.h"
 #include "WidevineFileIO.h"
 #include <mozilla/SizePrintfMacros.h>
 #include <stdarg.h>
 
+#include <utility>
+
 using namespace cdm;
 using namespace std;
 
 namespace mozilla {
 
 
 WidevineDecryptor::WidevineDecryptor()
   : mCallback(nullptr)
@@ -27,17 +29,17 @@ WidevineDecryptor::WidevineDecryptor()
 WidevineDecryptor::~WidevineDecryptor()
 {
   Log("WidevineDecryptor destroyed this=%p", this);
 }
 
 void
 WidevineDecryptor::SetCDM(RefPtr<CDMWrapper> aCDM)
 {
-  mCDM = aCDM;
+  mCDM = std::move(aCDM);
 }
 
 void
 WidevineDecryptor::Init(GMPDecryptorCallback* aCallback,
                         bool aDistinctiveIdentifierRequired,
                         bool aPersistentStateRequired)
 {
   Log("WidevineDecryptor::Init() this=%p distinctiveId=%d persistentState=%d",