Bug 1339537 - Part 6: Pass std::function values tree by const reference instead of by value, r=ehsan
authorMichael Layzell <michael@thelayzells.com>
Thu, 27 Apr 2017 12:44:57 -0400
changeset 355463 f1caa40c8c81678a0ae1844acd72a2f9fb7201a5
parent 355462 0fcbf84527ccb807d5d0a15a5246aad2f84631bb
child 355464 e9e4b447bf87b183cc7bb6007e35c1931828c319
push id31727
push usercbook@mozilla.com
push dateFri, 28 Apr 2017 08:36:40 +0000
treeherdermozilla-central@8f2b930cd028 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs1339537
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1339537 - Part 6: Pass std::function values tree by const reference instead of by value, r=ehsan MozReview-Commit-ID: PVAqU2DPs2
dom/audiochannel/AudioChannelService.cpp
dom/audiochannel/AudioChannelService.h
dom/canvas/ImageBitmapUtils.cpp
dom/ipc/ContentChild.cpp
dom/ipc/ContentChild.h
gfx/layers/ipc/LayerTreeOwnerTracker.cpp
gfx/layers/ipc/LayerTreeOwnerTracker.h
ipc/glue/MessageChannel.cpp
ipc/glue/MessageChannel.h
layout/generic/nsGridContainerFrame.cpp
layout/painting/FrameLayerBuilder.cpp
media/gmp-clearkey/0.1/ClearKeySessionManager.cpp
media/gmp-clearkey/0.1/ClearKeySessionManager.h
toolkit/components/url-classifier/Classifier.cpp
toolkit/components/url-classifier/Classifier.h
xpcom/base/NSPRLogModulesParser.cpp
xpcom/base/NSPRLogModulesParser.h
xpcom/ds/IncrementalTokenizer.cpp
xpcom/ds/IncrementalTokenizer.h
xpcom/ds/nsTObserverArray.h
--- a/dom/audiochannel/AudioChannelService.cpp
+++ b/dom/audiochannel/AudioChannelService.cpp
@@ -689,17 +689,17 @@ AudioChannelService::RefreshAgentsVolume
                                                    winData->mChannels[(uint32_t)aAudioChannel].mMuted);
   }
 
   RefreshAgentsVolume(aWindow);
 }
 
 void
 AudioChannelService::RefreshAgents(nsPIDOMWindowOuter* aWindow,
-                                   std::function<void(AudioChannelAgent*)> aFunc)
+                                   const std::function<void(AudioChannelAgent*)>& aFunc)
 {
   MOZ_ASSERT(aWindow);
   MOZ_ASSERT(aWindow->IsOuterWindow());
 
   nsCOMPtr<nsPIDOMWindowOuter> topWindow = aWindow->GetScriptableTop();
   if (!topWindow) {
     return;
   }
--- a/dom/audiochannel/AudioChannelService.h
+++ b/dom/audiochannel/AudioChannelService.h
@@ -210,17 +210,17 @@ public:
 
   void NotifyMediaResumedFromBlock(nsPIDOMWindowOuter* aWindow);
 
 private:
   AudioChannelService();
   ~AudioChannelService();
 
   void RefreshAgents(nsPIDOMWindowOuter* aWindow,
-                     std::function<void(AudioChannelAgent*)> aFunc);
+                     const std::function<void(AudioChannelAgent*)>& aFunc);
 
   static void CreateServiceIfNeeded();
 
   /**
    * Shutdown the singleton.
    */
   static void Shutdown();
 
--- a/dom/canvas/ImageBitmapUtils.cpp
+++ b/dom/canvas/ImageBitmapUtils.cpp
@@ -321,17 +321,17 @@ Utils::GetUtils(ImageBitmapFormat aForma
 /*
  * Helper functions.
  */
 template<typename SrcType, typename DstType>
 static UniquePtr<ImagePixelLayout>
 CvtSimpleImgToSimpleImg(Utils* aSrcUtils, const SrcType* aSrcBuffer,
                         const ImagePixelLayout* aSrcLayout, DstType* aDstBuffer,
                         ImageBitmapFormat aDstFormat, int aDstChannelCount,
-                        std::function<int (const SrcType*, int, DstType*, int, int, int)> converter)
+                        const std::function<int (const SrcType*, int, DstType*, int, int, int)>& converter)
 {
   MOZ_ASSERT(aSrcUtils, "Convert color from a null utility object.");
   MOZ_ASSERT(aSrcBuffer, "Convert color from a null buffer.");
   MOZ_ASSERT(aSrcLayout, "Convert color from a null layout.");
   MOZ_ASSERT(aDstBuffer, "Convert color to a null buffer.");
 
   const nsTArray<ChannelPixelLayout>& channels = *aSrcLayout;
   MOZ_ASSERT(channels.Length() == aSrcUtils->GetChannelCount(),
@@ -349,17 +349,17 @@ CvtSimpleImgToSimpleImg(Utils* aSrcUtils
   return CreateDefaultPixelLayout(aDstFormat, channels[0].mWidth,
                                   channels[0].mHeight, dstStride);
 }
 
 static UniquePtr<ImagePixelLayout>
 CvtYUVImgToSimpleImg(Utils* aSrcUtils, const uint8_t* aSrcBuffer,
                      const ImagePixelLayout* aSrcLayout, uint8_t* aDstBuffer,
                      ImageBitmapFormat aDstFormat, int aDstChannelCount,
-                     std::function<int (const uint8_t*, int, const uint8_t*, int, const uint8_t*, int, uint8_t*, int, int, int)> converter)
+                     const std::function<int (const uint8_t*, int, const uint8_t*, int, const uint8_t*, int, uint8_t*, int, int, int)>& converter)
 {
   MOZ_ASSERT(aSrcUtils, "Convert color from a null utility object.");
   MOZ_ASSERT(aSrcBuffer, "Convert color from a null buffer.");
   MOZ_ASSERT(aSrcLayout, "Convert color from a null layout.");
   MOZ_ASSERT(aDstBuffer, "Convert color to a null buffer.");
 
   const nsTArray<ChannelPixelLayout>& channels = *aSrcLayout;
   MOZ_ASSERT(channels.Length() == aSrcUtils->GetChannelCount(),
@@ -379,17 +379,17 @@ CvtYUVImgToSimpleImg(Utils* aSrcUtils, c
   return CreateDefaultPixelLayout(aDstFormat, channels[0].mWidth,
                                   channels[0].mHeight, dstStride);
 }
 
 static UniquePtr<ImagePixelLayout>
 CvtNVImgToSimpleImg(Utils* aSrcUtils, const uint8_t* aSrcBuffer,
                     const ImagePixelLayout* aSrcLayout, uint8_t* aDstBuffer,
                     ImageBitmapFormat aDstFormat, int aDstChannelCount,
-                    std::function<int (const uint8_t*, int, const uint8_t*, int, uint8_t*, int, int, int)> converter)
+                    const std::function<int (const uint8_t*, int, const uint8_t*, int, uint8_t*, int, int, int)>& converter)
 {
   MOZ_ASSERT(aSrcUtils, "Convert color from a null utility object.");
   MOZ_ASSERT(aSrcBuffer, "Convert color from a null buffer.");
   MOZ_ASSERT(aSrcLayout, "Convert color from a null layout.");
   MOZ_ASSERT(aDstBuffer, "Convert color to a null buffer.");
 
   const nsTArray<ChannelPixelLayout>& channels = *aSrcLayout;
   MOZ_ASSERT(channels.Length() == aSrcUtils->GetChannelCount(),
@@ -408,17 +408,17 @@ CvtNVImgToSimpleImg(Utils* aSrcUtils, co
   return CreateDefaultPixelLayout(aDstFormat, channels[0].mWidth,
                                   channels[0].mHeight, dstStride);
 }
 
 static UniquePtr<ImagePixelLayout>
 CvtSimpleImgToYUVImg(Utils* aSrcUtils, const uint8_t* aSrcBuffer,
                      const ImagePixelLayout* aSrcLayout, uint8_t* aDstBuffer,
                      ImageBitmapFormat aDstFormat,
-                     std::function<int (const uint8_t*, int, uint8_t*, int, uint8_t*, int, uint8_t*, int, int, int)> converter)
+                     const std::function<int (const uint8_t*, int, uint8_t*, int, uint8_t*, int, uint8_t*, int, int, int)>& converter)
 {
   MOZ_ASSERT(aSrcUtils, "Convert color from a null utility object.");
   MOZ_ASSERT(aSrcBuffer, "Convert color from a null buffer.");
   MOZ_ASSERT(aSrcLayout, "Convert color from a null layout.");
   MOZ_ASSERT(aDstBuffer, "Convert color to a null buffer.");
 
   UniquePtr<ImagePixelLayout> layout =
     CreateDefaultPixelLayout(aDstFormat, (*aSrcLayout)[0].mWidth,
@@ -440,17 +440,17 @@ CvtSimpleImgToYUVImg(Utils* aSrcUtils, c
 
   return layout;
 }
 
 static UniquePtr<ImagePixelLayout>
 CvtSimpleImgToNVImg(Utils* aSrcUtils, const uint8_t* aSrcBuffer,
                     const ImagePixelLayout* aSrcLayout, uint8_t* aDstBuffer,
                     ImageBitmapFormat aDstFormat,
-                    std::function<int (const uint8_t*, int, uint8_t*, int, uint8_t*, int, int, int)> converter)
+                    const std::function<int (const uint8_t*, int, uint8_t*, int, uint8_t*, int, int, int)>& converter)
 {
   MOZ_ASSERT(aSrcUtils, "Convert color from a null utility object.");
   MOZ_ASSERT(aSrcBuffer, "Convert color from a null buffer.");
   MOZ_ASSERT(aSrcLayout, "Convert color from a null layout.");
   MOZ_ASSERT(aDstBuffer, "Convert color to a null buffer.");
 
   UniquePtr<ImagePixelLayout> layout =
     CreateDefaultPixelLayout(aDstFormat, (*aSrcLayout)[0].mWidth,
--- a/dom/ipc/ContentChild.cpp
+++ b/dom/ipc/ContentChild.cpp
@@ -3366,17 +3366,17 @@ ContentChild::RecvProvideAnonymousTempor
     auto rawFD = aFDOrError.get_FileDescriptor().ClonePlatformHandle();
     prfile = PR_ImportFile(PROsfd(rawFD.release()));
   }
   (*callback)(prfile);
   return IPC_OK();
 }
 
 nsresult
-ContentChild::AsyncOpenAnonymousTemporaryFile(AnonymousTemporaryFileCallback aCallback)
+ContentChild::AsyncOpenAnonymousTemporaryFile(const AnonymousTemporaryFileCallback& aCallback)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   static uint64_t id = 0;
   auto newID = id++;
   if (!SendRequestAnonymousTemporaryFile(newID)) {
     return NS_ERROR_FAILURE;
   }
--- a/dom/ipc/ContentChild.h
+++ b/dom/ipc/ContentChild.h
@@ -659,17 +659,17 @@ public:
   void
   FileCreationRequest(nsID& aUUID, FileCreatorHelper* aHelper,
                       const nsAString& aFullPath, const nsAString& aType,
                       const nsAString& aName,
                       const Optional<int64_t>& aLastModified,
                       bool aExistenceCheck, bool aIsFromNsIFile);
 
   typedef std::function<void(PRFileDesc*)> AnonymousTemporaryFileCallback;
-  nsresult AsyncOpenAnonymousTemporaryFile(AnonymousTemporaryFileCallback aCallback);
+  nsresult AsyncOpenAnonymousTemporaryFile(const AnonymousTemporaryFileCallback& aCallback);
 
 private:
   static void ForceKillTimerCallback(nsITimer* aTimer, void* aClosure);
   void StartForceKillTimer();
 
   virtual void ActorDestroy(ActorDestroyReason why) override;
 
   virtual void ProcessingError(Result aCode, const char* aReason) override;
--- a/gfx/layers/ipc/LayerTreeOwnerTracker.cpp
+++ b/gfx/layers/ipc/LayerTreeOwnerTracker.cpp
@@ -66,17 +66,17 @@ LayerTreeOwnerTracker::IsMapped(uint64_t
 {
   MutexAutoLock lock(mLayerIdsLock);
 
   auto iter = mLayerIds.find(aLayersId);
   return iter != mLayerIds.end() && iter->second == aProcessId;
 }
 
 void
-LayerTreeOwnerTracker::Iterate(std::function<void(uint64_t aLayersId, base::ProcessId aProcessId)> aCallback)
+LayerTreeOwnerTracker::Iterate(const std::function<void(uint64_t aLayersId, base::ProcessId aProcessId)>& aCallback)
 {
   MutexAutoLock lock(mLayerIdsLock);
 
   for (const auto& iter : mLayerIds) {
     aCallback(iter.first, iter.second);
   }
 }
 
--- a/gfx/layers/ipc/LayerTreeOwnerTracker.h
+++ b/gfx/layers/ipc/LayerTreeOwnerTracker.h
@@ -51,17 +51,17 @@ public:
   */
   void Unmap(uint64_t aLayersId, base::ProcessId aProcessId);
 
   /**
    * Checks whether it is okay for aProcessId to access aLayersId.
    */
   bool IsMapped(uint64_t aLayersId, base::ProcessId aProcessId);
 
-  void Iterate(std::function<void(uint64_t aLayersId, base::ProcessId aProcessId)> aCallback);
+  void Iterate(const std::function<void(uint64_t aLayersId, base::ProcessId aProcessId)>& aCallback);
 
 private:
   LayerTreeOwnerTracker();
 
   mozilla::Mutex mLayerIdsLock;
   std::map<uint64_t, base::ProcessId> mLayerIds;
 };
 
--- a/ipc/glue/MessageChannel.cpp
+++ b/ipc/glue/MessageChannel.cpp
@@ -1202,17 +1202,17 @@ MessageChannel::OnMessageReceivedFromLin
     }
 
     if (shouldPostTask) {
         task->Post();
     }
 }
 
 void
-MessageChannel::PeekMessages(std::function<bool(const Message& aMsg)> aInvoke)
+MessageChannel::PeekMessages(const std::function<bool(const Message& aMsg)>& aInvoke)
 {
     // FIXME: We shouldn't be holding the lock for aInvoke!
     MonitorAutoLock lock(*mMonitor);
 
     for (MessageTask* it : mPending) {
         const Message &msg = it->Msg();
         if (!aInvoke(msg)) {
             break;
--- a/ipc/glue/MessageChannel.h
+++ b/ipc/glue/MessageChannel.h
@@ -147,17 +147,17 @@ class MessageChannel : HasResultCodes, M
     void SetAbortOnError(bool abort)
     {
         mAbortOnError = abort;
     }
 
     // Call aInvoke for each pending message until it returns false.
     // XXX: You must get permission from an IPC peer to use this function
     //      since it requires custom deserialization and re-orders events.
-    void PeekMessages(std::function<bool(const Message& aMsg)> aInvoke);
+    void PeekMessages(const std::function<bool(const Message& aMsg)>& aInvoke);
 
     // Misc. behavioral traits consumers can request for this channel
     enum ChannelFlags {
       REQUIRE_DEFAULT                         = 0,
       // Windows: if this channel operates on the UI thread, indicates
       // WindowsMessageLoop code should enable deferred native message
       // handling to prevent deadlocks. Should only be used for protocols
       // that manage child processes which might create native UI, like
--- a/layout/generic/nsGridContainerFrame.cpp
+++ b/layout/generic/nsGridContainerFrame.cpp
@@ -1223,17 +1223,17 @@ struct nsGridContainerFrame::Tracks
   /**
    * Grow the planned size for tracks in aGrowableTracks up to their limit
    * and then freeze them (all aGrowableTracks must be unfrozen on entry).
    * Subtract the space added from aAvailableSpace and return that.
    */
   nscoord GrowTracksToLimit(nscoord                   aAvailableSpace,
                             nsTArray<TrackSize>&      aPlan,
                             const nsTArray<uint32_t>& aGrowableTracks,
-                            FitContentClamper         aFitContentClamper) const
+                            const FitContentClamper&  aFitContentClamper) const
   {
     MOZ_ASSERT(aAvailableSpace > 0 && aGrowableTracks.Length() > 0);
     nscoord space = aAvailableSpace;
     uint32_t numGrowable = aGrowableTracks.Length();
     while (true) {
       nscoord spacePerTrack = std::max<nscoord>(space / numGrowable, 1);
       for (uint32_t track : aGrowableTracks) {
         TrackSize& sz = aPlan[track];
@@ -1318,17 +1318,17 @@ struct nsGridContainerFrame::Tracks
    * aSelector (or all tracks if aSelector is zero) beyond their limit.
    * This implements the "Distribute space beyond growth limits" step in
    * https://drafts.csswg.org/css-grid/#distribute-extra-space
    */
   void GrowSelectedTracksUnlimited(nscoord                   aAvailableSpace,
                                    nsTArray<TrackSize>&      aPlan,
                                    const nsTArray<uint32_t>& aGrowableTracks,
                                    TrackSize::StateBits      aSelector,
-                                   FitContentClamper aFitContentClamper) const
+                                   const FitContentClamper&  aFitContentClamper) const
   {
     MOZ_ASSERT(aAvailableSpace > 0 && aGrowableTracks.Length() > 0);
     uint32_t numGrowable = aGrowableTracks.Length();
     if (aSelector) {
       MOZ_ASSERT(aSelector == (aSelector & TrackSize::eIntrinsicMinSizing) &&
                  (aSelector & TrackSize::eMaxContentMinSizing),
                  "Should only get here for track sizing steps 2.1 to 2.3");
       // Note that eMaxContentMinSizing is always included. We do those first:
--- a/layout/painting/FrameLayerBuilder.cpp
+++ b/layout/painting/FrameLayerBuilder.cpp
@@ -1279,17 +1279,17 @@ protected:
    * Since mask layers can exist either on the layer directly, or as a side-
    * attachment to FrameMetrics (for ancestor scrollframe clips), we key the
    * recycle operation on both the originating layer and the mask layer's
    * index in the layer, if any.
    */
   struct MaskLayerKey;
   already_AddRefed<ImageLayer>
   CreateOrRecycleMaskImageLayerFor(const MaskLayerKey& aKey,
-                                   std::function<void(Layer* aLayer)> aSetUserData);
+                                   const std::function<void(Layer* aLayer)>& aSetUserData);
   /**
    * Grabs all PaintedLayers and ColorLayers from the ContainerLayer and makes them
    * available for recycling.
    */
   void CollectOldLayers();
   /**
    * If aItem used to belong to a PaintedLayer, invalidates the area of
    * aItem in that layer. If aNewLayer is a PaintedLayer, invalidates the area of
@@ -2215,17 +2215,17 @@ ContainerState::CreateOrRecycleImageLaye
     // Remove other layer types we might have stored for this PaintedLayer
     data->mColorLayer = nullptr;
   }
   return layer.forget();
 }
 
 already_AddRefed<ImageLayer>
 ContainerState::CreateOrRecycleMaskImageLayerFor(const MaskLayerKey& aKey,
-                                                 std::function<void(Layer* aLayer)> aSetUserData)
+                                                 const std::function<void(Layer* aLayer)>& aSetUserData)
 {
   RefPtr<ImageLayer> result = mRecycledMaskImageLayers.Get(aKey);
   if (result) {
     mRecycledMaskImageLayers.Remove(aKey);
     aKey.mLayer->ClearExtraDumpInfo();
     // XXX if we use clip on mask layers, null it out here
   } else {
     // Create a new layer
--- a/media/gmp-clearkey/0.1/ClearKeySessionManager.cpp
+++ b/media/gmp-clearkey/0.1/ClearKeySessionManager.cpp
@@ -89,17 +89,17 @@ ClearKeySessionManager::CreateSession(ui
     self->CreateSession(aPromiseId,
                         aInitDataType,
                         initData.data(),
                         initData.size(),
                         aSessionType);
   };
 
   // If we haven't loaded, don't do this yet
-  if (MaybeDeferTillInitialized(deferrer)) {
+  if (MaybeDeferTillInitialized(move(deferrer))) {
     CK_LOGD("Deferring CreateSession");
     return;
   }
 
   CK_LOGARRAY("ClearKeySessionManager::CreateSession initdata: ",
               aInitData,
               aInitDataSize);
 
@@ -197,17 +197,17 @@ ClearKeySessionManager::LoadSession(uint
   // we try to use it.
   RefPtr<ClearKeySessionManager> self(this);
   function<void()> deferrer =
     [self, aPromiseId, sessionId] ()
   {
     self->LoadSession(aPromiseId, sessionId.data(), sessionId.size());
   };
 
-  if (MaybeDeferTillInitialized(deferrer)) {
+  if (MaybeDeferTillInitialized(move(deferrer))) {
     CK_LOGD("Deferring LoadSession");
     return;
   }
 
   // If the SessionManager has been shutdown mHost will be null and we won't
   // be able to resolve the promise.
   if (!mHost) {
     return;
@@ -333,17 +333,17 @@ ClearKeySessionManager::UpdateSession(ui
     self->UpdateSession(aPromiseId,
                         sessionId.data(),
                         sessionId.size(),
                         response.data(),
                         response.size());
   };
 
   // If we haven't fully loaded, defer calling this method
-  if (MaybeDeferTillInitialized(deferrer)) {
+  if (MaybeDeferTillInitialized(move(deferrer))) {
     CK_LOGD("Deferring LoadSession");
     return;
   }
 
   // Make sure the SessionManager has not been shutdown before we try and
   // resolve any promises.
   if (!mHost) {
     return;
@@ -483,17 +483,17 @@ ClearKeySessionManager::CloseSession(uin
   RefPtr<ClearKeySessionManager> self(this);
   function<void()> deferrer =
     [self, aPromiseId, sessionId] ()
   {
     self->CloseSession(aPromiseId, sessionId.data(), sessionId.size());
   };
 
   // If we haven't loaded, call this method later.
-  if (MaybeDeferTillInitialized(deferrer)) {
+  if (MaybeDeferTillInitialized(move(deferrer))) {
     CK_LOGD("Deferring CloseSession");
     return;
   }
 
   // If DecryptingComplete has been called mHost will be null and we won't
   // be able to resolve our promise.
   if (!mHost) {
     return;
@@ -542,17 +542,17 @@ ClearKeySessionManager::RemoveSession(ui
   RefPtr<ClearKeySessionManager> self(this);
   function<void()> deferrer =
     [self, aPromiseId, sessionId] ()
   {
     self->RemoveSession(aPromiseId, sessionId.data(), sessionId.size());
   };
 
   // If we haven't fully loaded, defer calling this method.
-  if (MaybeDeferTillInitialized(deferrer)) {
+  if (MaybeDeferTillInitialized(move(deferrer))) {
     CK_LOGD("Deferring RemoveSession");
     return;
   }
 
   // Check that the SessionManager has not been shutdown before we try and
   // resolve any promises.
   if (!mHost) {
     return;
@@ -660,17 +660,17 @@ ClearKeySessionManager::DecryptingComple
   mSessions.clear();
 
   mDecryptionManager = nullptr;
   mHost = nullptr;
 
   Release();
 }
 
-bool ClearKeySessionManager::MaybeDeferTillInitialized(function<void()> aMaybeDefer)
+bool ClearKeySessionManager::MaybeDeferTillInitialized(function<void()>&& aMaybeDefer)
 {
   if (mPersistence->IsLoaded()) {
     return false;
   }
 
   mDeferredInitialize.emplace(move(aMaybeDefer));
   return true;
 }
--- a/media/gmp-clearkey/0.1/ClearKeySessionManager.h
+++ b/media/gmp-clearkey/0.1/ClearKeySessionManager.h
@@ -79,17 +79,17 @@ public:
                                    const std::string& aSessionId,
                                    const uint8_t* aKeyData,
                                    uint32_t aKeyDataSize);
 
 private:
   ~ClearKeySessionManager();
 
   void ClearInMemorySessionData(ClearKeySession* aSession);
-  bool MaybeDeferTillInitialized(std::function<void()> aMaybeDefer);
+  bool MaybeDeferTillInitialized(std::function<void()>&& aMaybeDefer);
   void Serialize(const ClearKeySession* aSession,
                  std::vector<uint8_t>& aOutKeyData);
 
   RefPtr<ClearKeyDecryptionManager> mDecryptionManager;
   RefPtr<ClearKeyPersistence> mPersistence;
 
   cdm::Host_8* mHost = nullptr;
 
--- a/toolkit/components/url-classifier/Classifier.cpp
+++ b/toolkit/components/url-classifier/Classifier.cpp
@@ -719,17 +719,17 @@ void Classifier::FlushAndDisableAsyncUpd
   }
 
   mUpdateThread->Shutdown();
   mUpdateThread = nullptr;
 }
 
 nsresult
 Classifier::AsyncApplyUpdates(nsTArray<TableUpdate*>* aUpdates,
-                              AsyncUpdateCallback aCallback)
+                              const AsyncUpdateCallback& aCallback)
 {
   LOG(("Classifier::AsyncApplyUpdates"));
 
   if (!mUpdateThread) {
     LOG(("Async update has already been disabled."));
     return NS_ERROR_FAILURE;
   }
 
--- a/toolkit/components/url-classifier/Classifier.h
+++ b/toolkit/components/url-classifier/Classifier.h
@@ -67,17 +67,17 @@ public:
    * Asynchronously apply updates to the in-use databases. When the
    * update is complete, the caller can be notified by |aCallback|, which
    * will occur on the caller thread. Note that the ownership of
    * |aUpdates| will be transferred. This design is inherited from the
    * previous sync update function (ApplyUpdates) which has been removed.
    */
   using AsyncUpdateCallback = std::function<void(nsresult)>;
   nsresult AsyncApplyUpdates(nsTArray<TableUpdate*>* aUpdates,
-                             AsyncUpdateCallback aCallback);
+                             const AsyncUpdateCallback& aCallback);
 
   /**
    * Wait until the ongoing async update is finished and callback
    * is fired. Once this function returns, AsyncApplyUpdates is
    * no longer available.
    */
   void FlushAndDisableAsyncUpdate();
 
--- a/xpcom/base/NSPRLogModulesParser.cpp
+++ b/xpcom/base/NSPRLogModulesParser.cpp
@@ -10,17 +10,17 @@
 
 const char kDelimiters[] = ", ";
 const char kAdditionalWordChars[] = "_-";
 
 namespace mozilla {
 
 void
 NSPRLogModulesParser(const char* aLogModules,
-                     std::function<void(const char*, LogLevel, int32_t)> aCallback)
+                     const std::function<void(const char*, LogLevel, int32_t)>& aCallback)
 {
   if (!aLogModules) {
     return;
   }
 
   Tokenizer parser(aLogModules, kDelimiters, kAdditionalWordChars);
   nsAutoCString moduleName;
 
--- a/xpcom/base/NSPRLogModulesParser.h
+++ b/xpcom/base/NSPRLogModulesParser.h
@@ -13,11 +13,11 @@ namespace mozilla {
 /**
  * Helper function that parses the legacy NSPR_LOG_MODULES env var format
  * for specifying log levels and logging options.
  *
  * @param aLogModules The log modules configuration string.
  * @param aCallback The callback to invoke for each log module config entry.
  */
 void NSPRLogModulesParser(const char* aLogModules,
-                          std::function<void(const char*, LogLevel, int32_t)> aCallback);
+                          const std::function<void(const char*, LogLevel, int32_t)>& aCallback);
 
 } // namespace mozilla
--- a/xpcom/ds/IncrementalTokenizer.cpp
+++ b/xpcom/ds/IncrementalTokenizer.cpp
@@ -9,28 +9,28 @@
 #include "mozilla/AutoRestore.h"
 
 #include "nsIInputStream.h"
 #include "IncrementalTokenizer.h"
 #include <algorithm>
 
 namespace mozilla {
 
-IncrementalTokenizer::IncrementalTokenizer(Consumer aConsumer,
+IncrementalTokenizer::IncrementalTokenizer(Consumer&& aConsumer,
                                            const char * aWhitespaces,
                                            const char * aAdditionalWordChars,
                                            uint32_t aRawMinBuffered)
   : TokenizerBase(aWhitespaces, aAdditionalWordChars)
 #ifdef DEBUG
   , mConsuming(false)
 #endif
   , mNeedMoreInput(false)
   , mRollback(false)
   , mInputCursor(0)
-  , mConsumer(aConsumer)
+  , mConsumer(Move(aConsumer))
 {
   mInputFinished = false;
   mMinRawDelivery = aRawMinBuffered;
 }
 
 nsresult IncrementalTokenizer::FeedInput(const nsACString & aInput)
 {
   NS_ENSURE_TRUE(mConsumer, NS_ERROR_NOT_INITIALIZED);
--- a/xpcom/ds/IncrementalTokenizer.h
+++ b/xpcom/ds/IncrementalTokenizer.h
@@ -38,17 +38,17 @@ public:
    *    A mandatory non-null argument, a function that consumes the tokens as they
    *    come when the tokenizer is fed.
    * @param aRawMinBuffered
    *    When we have buffered at least aRawMinBuffered data, but there was no custom
    *    token found so far because of too small incremental feed chunks, deliver
    *    the raw data to preserve streaming and to save memory.  This only has effect
    *    in OnlyCustomTokenizing mode.
    */
-  explicit IncrementalTokenizer(Consumer aConsumer,
+  explicit IncrementalTokenizer(Consumer&& aConsumer,
                                 const char* aWhitespaces = nullptr,
                                 const char* aAdditionalWordChars = nullptr,
                                 uint32_t aRawMinBuffered = 1024);
 
   /**
    * Pushes the input to be tokenized.  These directly call the Consumer callback
    * on every found token.  Result of the Consumer callback is returned here.
    *
--- a/xpcom/ds/nsTObserverArray.h
+++ b/xpcom/ds/nsTObserverArray.h
@@ -246,17 +246,17 @@ public:
     }
 
     mArray.RemoveElementAt(index);
     AdjustIterators(index, -1);
     return true;
   }
 
   // See nsTArray::RemoveElementsBy.
-  void RemoveElementsBy(std::function<bool(const elem_type&)> aPredicate)
+  void RemoveElementsBy(const std::function<bool(const elem_type&)>& aPredicate)
   {
     index_type i = 0;
     mArray.RemoveElementsBy([&](const elem_type& aItem) {
       if (aPredicate(aItem)) {
         // This element is going to be removed.
         AdjustIterators(i, -1);
         return true;
       }