Bug 1443428 - Remove some unnecessary copies by declaring them as const r?ehsan draft
authorSylvestre Ledru <sledru@mozilla.com>
Tue, 06 Mar 2018 09:57:12 +0100
changeset 763675 3fc217d09a458b50066156d29948a151aa53a41b
parent 763128 8bfd4555d81d7279a6dff97c965c83b7691c3166
child 765897 b54c375e96ac2b570f607f39cb500792695f4a88
push id101521
push usersledru@mozilla.com
push dateTue, 06 Mar 2018 13:26:08 +0000
reviewersehsan
bugs1443428
milestone60.0a1
Bug 1443428 - Remove some unnecessary copies by declaring them as const r?ehsan MozReview-Commit-ID: 312xekF03At
devtools/shared/heapsnapshot/HeapSnapshot.cpp
dom/base/nsContentSink.cpp
dom/base/nsRange.cpp
dom/indexedDB/ActorsParent.cpp
dom/ipc/ContentChild.cpp
dom/ipc/TabChild.cpp
dom/ipc/TabParent.cpp
dom/media/gmp/GMPServiceChild.cpp
dom/media/ipc/VideoDecoderManagerChild.cpp
dom/storage/StorageDBThread.cpp
gfx/layers/AnimationHelper.cpp
gfx/layers/apz/src/AsyncPanZoomController.cpp
gfx/layers/basic/BasicLayersImpl.cpp
gfx/layers/composite/AsyncCompositionManager.cpp
gfx/layers/ipc/LayerTransactionParent.cpp
js/src/vm/JSAtom.cpp
layout/base/nsCSSFrameConstructor.cpp
layout/base/nsLayoutUtils.cpp
layout/forms/nsButtonFrameRenderer.cpp
layout/generic/nsFrame.cpp
layout/generic/nsGridContainerFrame.cpp
layout/generic/nsSimplePageSequenceFrame.cpp
layout/painting/nsDisplayList.cpp
layout/svg/nsSVGPatternFrame.cpp
toolkit/components/extensions/WebExtensionPolicy.cpp
toolkit/components/url-classifier/ProtocolParser.cpp
uriloader/exthandler/ContentHandlerService.cpp
widget/nsClipboardProxy.cpp
--- a/devtools/shared/heapsnapshot/HeapSnapshot.cpp
+++ b/devtools/shared/heapsnapshot/HeapSnapshot.cpp
@@ -313,17 +313,17 @@ HeapSnapshot::saveStackFrame(const proto
     outFrameId = frame.ref();
     return true;
   }
 
   // Incomplete message.
   if (!frame.has_data())
     return false;
 
-  auto data = frame.data();
+  const auto& data = frame.data();
 
   if (!data.has_id())
     return false;
   StackFrameId id = data.id();
 
   // This should be the first and only time we see this frame.
   if (frames.has(id))
     return false;
--- a/dom/base/nsContentSink.cpp
+++ b/dom/base/nsContentSink.cpp
@@ -1260,17 +1260,17 @@ nsContentSink::StartLayout(bool aIgnoreP
   mDocument->SetMayStartLayout(true);
   nsCOMPtr<nsIPresShell> shell = mDocument->GetShell();
   // Make sure we don't call Initialize() for a shell that has
   // already called it. This can happen when the layout frame for
   // an iframe is constructed *between* the Embed() call for the
   // docshell in the iframe, and the content sink's call to OpenBody().
   // (Bug 153815)
   if (shell && !shell->DidInitialize()) {
-    nsCOMPtr<nsIPresShell> shellGrip = shell;
+    const nsCOMPtr<nsIPresShell>& shellGrip = shell;
     nsresult rv = shell->Initialize();
     if (NS_FAILED(rv)) {
       return;
     }
   }
 
   // If the document we are loading has a reference or it is a
   // frameset document, disable the scroll bars on the views.
--- a/dom/base/nsRange.cpp
+++ b/dom/base/nsRange.cpp
@@ -2464,17 +2464,17 @@ nsRange::CutContents(DocumentFragment** 
       res.WouldReportJSException();
       if (NS_WARN_IF(res.Failed())) {
         return res.StealNSResult();
       }
       NS_ENSURE_STATE(!guard.Mutated(parent ? 2 : 1) ||
                       ValidateCurrentNode(this, iter));
     } else if (nodeToResult) {
       nsMutationGuard guard;
-      nsCOMPtr<nsINode> node = nodeToResult;
+      const nsCOMPtr<nsINode>& node = nodeToResult;
       nsCOMPtr<nsINode> parent = node->GetParentNode();
       if (parent) {
         mozilla::ErrorResult error;
         parent->RemoveChild(*node, error);
         NS_ENSURE_FALSE(error.Failed(), error.StealNSResult());
       }
       NS_ENSURE_STATE(!guard.Mutated(1) ||
                       ValidateCurrentNode(this, iter));
--- a/dom/indexedDB/ActorsParent.cpp
+++ b/dom/indexedDB/ActorsParent.cpp
@@ -15218,17 +15218,17 @@ TransactionBase::VerifyRequestParams(con
   if (NS_WARN_IF(!aParams.cloneInfo().data().data.Size())) {
     ASSERT_UNLESS_FUZZING();
     return false;
   }
 
   if (objMetadata->mCommonMetadata.autoIncrement() &&
       objMetadata->mCommonMetadata.keyPath().IsValid() &&
       aParams.key().IsUnset()) {
-    const SerializedStructuredCloneWriteInfo cloneInfo = aParams.cloneInfo();
+    const SerializedStructuredCloneWriteInfo& cloneInfo = aParams.cloneInfo();
 
     if (NS_WARN_IF(!cloneInfo.offsetToKeyProp())) {
       ASSERT_UNLESS_FUZZING();
       return false;
     }
 
     if (NS_WARN_IF(cloneInfo.data().data.Size() < sizeof(uint64_t))) {
       ASSERT_UNLESS_FUZZING();
--- a/dom/ipc/ContentChild.cpp
+++ b/dom/ipc/ContentChild.cpp
@@ -914,17 +914,17 @@ ContentChild::ProvideWindowCommon(TabChi
 
   // NOTE: Capturing by reference here is safe, as this function won't return
   // until one of these callbacks is called.
   auto resolve = [&] (const CreatedWindowInfo& info) {
     MOZ_RELEASE_ASSERT(NS_IsMainThread());
     rv = info.rv();
     *aWindowIsNew = info.windowOpened();
     nsTArray<FrameScriptInfo> frameScripts(info.frameScripts());
-    nsCString urlToLoad = info.urlToLoad();
+    const nsCString& urlToLoad = info.urlToLoad();
     TextureFactoryIdentifier textureFactoryIdentifier = info.textureFactoryIdentifier();
     uint64_t layersId = info.layersId();
     CompositorOptions compositorOptions = info.compositorOptions();
     uint32_t maxTouchPoints = info.maxTouchPoints();
     DimensionInfo dimensionInfo = info.dimensions();
 
     // Once this function exits, we should try to exit the nested event loop.
     ready = true;
--- a/dom/ipc/TabChild.cpp
+++ b/dom/ipc/TabChild.cpp
@@ -2014,17 +2014,17 @@ TabChild::RequestEditCommands(nsIWidget:
     case nsIWidget::NativeKeyBindingsForRichTextEditor:
       break;
     default:
       MOZ_ASSERT_UNREACHABLE("Invalid native key bindings type");
   }
 
   // Don't send aEvent to the parent process directly because it'll be marked
   // as posted to remote process.
-  WidgetKeyboardEvent localEvent(aEvent);
+  const WidgetKeyboardEvent& localEvent(aEvent);
   SendRequestNativeKeyBindings(aType, localEvent, &aCommands);
 }
 
 mozilla::ipc::IPCResult
 TabChild::RecvNativeSynthesisResponse(const uint64_t& aObserverId,
                                       const nsCString& aResponse)
 {
   mozilla::widget::AutoObserverNotifier::NotifySavedObserver(aObserverId,
--- a/dom/ipc/TabParent.cpp
+++ b/dom/ipc/TabParent.cpp
@@ -843,17 +843,17 @@ TabParent::ThemeChanged()
 void
 TabParent::HandleAccessKey(const WidgetKeyboardEvent& aEvent,
                            nsTArray<uint32_t>& aCharCodes)
 {
   if (!mIsDestroyed) {
     // Note that we don't need to mark aEvent is posted to a remote process
     // because the event may be dispatched to it as normal keyboard event.
     // Therefore, we should use local copy to send it.
-    WidgetKeyboardEvent localEvent(aEvent);
+    const WidgetKeyboardEvent& localEvent(aEvent);
     Unused << SendHandleAccessKey(localEvent, aCharCodes);
   }
 }
 
 void
 TabParent::Activate()
 {
   if (!mIsDestroyed) {
--- a/dom/media/gmp/GMPServiceChild.cpp
+++ b/dom/media/gmp/GMPServiceChild.cpp
@@ -61,18 +61,18 @@ GeckoMediaPluginServiceChild::GetContent
 {
   MOZ_ASSERT(mGMPThread->EventTarget()->IsOnCurrentThread());
 
   MozPromiseHolder<GetGMPContentParentPromise>* rawHolder = new MozPromiseHolder<GetGMPContentParentPromise>();
   RefPtr<GetGMPContentParentPromise> promise = rawHolder->Ensure(__func__);
   RefPtr<AbstractThread> thread(GetAbstractGMPThread());
 
   nsCString nodeIdString(aNodeIdString);
-  nsCString api(aAPI);
-  nsTArray<nsCString> tags(aTags);
+  const nsCString& api(aAPI);
+  const nsTArray<nsCString>& tags(aTags);
   RefPtr<GMPCrashHelper> helper(aHelper);
   RefPtr<GeckoMediaPluginServiceChild> self(this);
   GetServiceChild()->Then(
     thread,
     __func__,
     [self, nodeIdString, api, tags, helper, rawHolder](GMPServiceChild* child) {
       UniquePtr<MozPromiseHolder<GetGMPContentParentPromise>> holder(rawHolder);
       nsresult rv;
@@ -144,18 +144,18 @@ GeckoMediaPluginServiceChild::GetContent
   MOZ_ASSERT(mGMPThread->EventTarget()->IsOnCurrentThread());
 
   MozPromiseHolder<GetGMPContentParentPromise>* rawHolder =
     new MozPromiseHolder<GetGMPContentParentPromise>();
   RefPtr<GetGMPContentParentPromise> promise = rawHolder->Ensure(__func__);
   RefPtr<AbstractThread> thread(GetAbstractGMPThread());
 
   NodeIdData nodeId(aNodeId.mOrigin, aNodeId.mTopLevelOrigin, aNodeId.mGMPName);
-  nsCString api(aAPI);
-  nsTArray<nsCString> tags(aTags);
+  const nsCString& api(aAPI);
+  const nsTArray<nsCString>& tags(aTags);
   RefPtr<GMPCrashHelper> helper(aHelper);
   RefPtr<GeckoMediaPluginServiceChild> self(this);
   GetServiceChild()->Then(
     thread,
     __func__,
     [self, nodeId, api, tags, helper, rawHolder](GMPServiceChild* child) {
       UniquePtr<MozPromiseHolder<GetGMPContentParentPromise>> holder(rawHolder);
       nsresult rv;
--- a/dom/media/ipc/VideoDecoderManagerChild.cpp
+++ b/dom/media/ipc/VideoDecoderManagerChild.cpp
@@ -180,17 +180,17 @@ VideoDecoderManagerChild::CanSend()
   return mCanSend;
 }
 
 bool
 VideoDecoderManagerChild::DeallocShmem(mozilla::ipc::Shmem& aShmem)
 {
   if (NS_GetCurrentThread() != sVideoDecoderChildThread) {
     RefPtr<VideoDecoderManagerChild> self = this;
-    mozilla::ipc::Shmem shmem = aShmem;
+    const mozilla::ipc::Shmem& shmem = aShmem;
     sVideoDecoderChildThread->Dispatch(
       NS_NewRunnableFunction("dom::VideoDecoderManagerChild::DeallocShmem",
                              [self, shmem]() {
                                if (self->CanSend()) {
                                  mozilla::ipc::Shmem shmemCopy = shmem;
                                  self->DeallocShmem(shmemCopy);
                                }
                              }),
@@ -261,17 +261,17 @@ VideoDecoderManagerChild::Readback(const
 
   return source.forget();
 }
 
 void
 VideoDecoderManagerChild::DeallocateSurfaceDescriptorGPUVideo(const SurfaceDescriptorGPUVideo& aSD)
 {
   RefPtr<VideoDecoderManagerChild> ref = this;
-  SurfaceDescriptorGPUVideo sd = Move(aSD);
+  const SurfaceDescriptorGPUVideo& sd = Move(aSD);
   sVideoDecoderChildThread->Dispatch(
     NS_NewRunnableFunction(
       "dom::VideoDecoderManagerChild::DeallocateSurfaceDescriptorGPUVideo",
       [ref, sd]() {
         if (ref->CanSend()) {
           ref->SendDeallocateSurfaceDescriptorGPUVideo(sd);
         }
       }),
--- a/dom/storage/StorageDBThread.cpp
+++ b/dom/storage/StorageDBThread.cpp
@@ -56,17 +56,17 @@ bool sStorageThreadDown = false;
 
 // This is only a compatibility code for schema version 0.  Returns the 'scope'
 // key in the schema version 0 format for the scope column.
 nsCString
 Scheme0Scope(LocalStorageCacheBridge* aCache)
 {
   nsCString result;
 
-  nsCString suffix = aCache->OriginSuffix();
+  const nsCString& suffix = aCache->OriginSuffix();
 
   OriginAttributes oa;
   if (!suffix.IsEmpty()) {
     DebugOnly<bool> success = oa.PopulateFromSuffix(suffix);
     MOZ_ASSERT(success);
   }
 
   if (oa.mAppId != nsIScriptSecurityManager::NO_APP_ID ||
--- a/gfx/layers/AnimationHelper.cpp
+++ b/gfx/layers/AnimationHelper.cpp
@@ -539,17 +539,17 @@ AnimationHelper::SetAnimations(Animation
     InfallibleTArray<AnimationValue>& startValues = data->mStartValues;
     InfallibleTArray<AnimationValue>& endValues = data->mEndValues;
 
     const InfallibleTArray<AnimationSegment>& segments = animation.segments();
     for (const AnimationSegment& segment : segments) {
       startValues.AppendElement(ToAnimationValue(segment.startState()));
       endValues.AppendElement(ToAnimationValue(segment.endState()));
 
-      TimingFunction tf = segment.sampleFn();
+      const TimingFunction& tf = segment.sampleFn();
       Maybe<ComputedTimingFunction> ctf =
         AnimationUtils::TimingFunctionToComputedTimingFunction(tf);
       functions.AppendElement(ctf);
     }
   }
 }
 
 uint64_t
@@ -601,17 +601,17 @@ AnimationHelper::SampleAnimations(Compos
       case eCSSProperty_opacity: {
         aStorage->SetAnimatedValue(iter.Key(), animationValue.GetOpacity());
         break;
       }
       case eCSSProperty_transform: {
         RefPtr<const nsCSSValueSharedList> list =
           animationValue.GetTransformList();
         const TransformData& transformData = animation.data().get_TransformData();
-        nsPoint origin = transformData.origin();
+        const nsPoint& origin = transformData.origin();
         // we expect all our transform data to arrive in device pixels
         gfx::Point3D transformOrigin = transformData.transformOrigin();
         nsDisplayTransform::FrameTransformProperties props(Move(list),
                                                            transformOrigin);
 
         gfx::Matrix4x4 transform =
           nsDisplayTransform::GetResultingTransformMatrix(props, origin,
                                                           transformData.appUnitsPerDevPixel(),
--- a/gfx/layers/apz/src/AsyncPanZoomController.cpp
+++ b/gfx/layers/apz/src/AsyncPanZoomController.cpp
@@ -1085,17 +1085,17 @@ nsEventStatus AsyncPanZoomController::Ha
     if (!tapInput.TransformToLocal(aTransformToApzc)) {
       return rv;
     }
 
     rv = HandleGestureEvent(tapInput);
     break;
   }
   case KEYBOARD_INPUT: {
-    KeyboardInput keyInput = aEvent.AsKeyboardInput();
+    const KeyboardInput& keyInput = aEvent.AsKeyboardInput();
     rv = OnKeyboard(keyInput);
     break;
   }
   }
 
   return rv;
 }
 
--- a/gfx/layers/basic/BasicLayersImpl.cpp
+++ b/gfx/layers/basic/BasicLayersImpl.cpp
@@ -24,17 +24,17 @@ GetMaskData(Layer* aMaskLayer,
             const Point& aDeviceOffset,
             AutoMoz2DMaskData* aMaskData)
 {
   if (aMaskLayer) {
     RefPtr<SourceSurface> surface =
       static_cast<BasicImplData*>(aMaskLayer->ImplData())->GetAsSourceSurface();
     if (surface) {
       Matrix transform;
-      Matrix4x4 effectiveTransform = aMaskLayer->GetEffectiveTransform();
+      const Matrix4x4& effectiveTransform = aMaskLayer->GetEffectiveTransform();
       DebugOnly<bool> maskIs2D = effectiveTransform.CanDraw2D(&transform);
       NS_ASSERTION(maskIs2D, "How did we end up with a 3D transform here?!");
       transform.PostTranslate(-aDeviceOffset.x, -aDeviceOffset.y);
       aMaskData->Construct(transform, surface);
       return true;
     }
   }
   return false;
--- a/gfx/layers/composite/AsyncCompositionManager.cpp
+++ b/gfx/layers/composite/AsyncCompositionManager.cpp
@@ -594,17 +594,17 @@ ApplyAnimatedValue(Layer* aLayer,
       aStorage->SetAnimatedValue(aLayer->GetCompositorAnimationsId(),
                                  aValue.GetOpacity());
 
       break;
     }
     case eCSSProperty_transform: {
       RefPtr<const nsCSSValueSharedList> list = aValue.GetTransformList();
       const TransformData& transformData = aAnimationData.get_TransformData();
-      nsPoint origin = transformData.origin();
+      const nsPoint& origin = transformData.origin();
       // we expect all our transform data to arrive in device pixels
       Point3D transformOrigin = transformData.transformOrigin();
       nsDisplayTransform::FrameTransformProperties props(Move(list),
                                                          transformOrigin);
 
       Matrix4x4 transform =
         nsDisplayTransform::GetResultingTransformMatrix(props, origin,
                                                         transformData.appUnitsPerDevPixel(),
@@ -1261,17 +1261,17 @@ AsyncCompositionManager::ComputeTransfor
   // Note that since the async transform is applied on top of the content's
   // regular transform, we need to make sure to unapply the async transform in
   // the same coordinate space. This requires applying the content transform
   // and then unapplying it after unapplying the async transform.
   if (aScrollbarIsDescendant) {
     AsyncTransformComponentMatrix overscroll =
         aApzc->GetOverscrollTransform(AsyncPanZoomController::eForCompositing);
     Matrix4x4 asyncUntransform = (asyncTransform * overscroll).Inverse().ToUnknownMatrix();
-    Matrix4x4 contentTransform = aScrollableContentTransform;
+    const Matrix4x4& contentTransform = aScrollableContentTransform;
     Matrix4x4 contentUntransform = contentTransform.Inverse();
 
     AsyncTransformComponentMatrix asyncCompensation =
         ViewAs<AsyncTransformComponentMatrix>(
             contentTransform
           * asyncUntransform
           * contentUntransform);
 
--- a/gfx/layers/ipc/LayerTransactionParent.cpp
+++ b/gfx/layers/ipc/LayerTransactionParent.cpp
@@ -528,17 +528,17 @@ LayerTransactionParent::SetLayerAttribut
     UpdateHitTestingTree(layer, "event regions changed");
     layer->SetEventRegions(common.eventRegions());
   }
   Maybe<ParentLayerIntRect> clipRect = common.useClipRect() ? Some(common.clipRect()) : Nothing();
   if (clipRect != layer->GetClipRect()) {
     UpdateHitTestingTree(layer, "clip rect changed");
     layer->SetClipRect(clipRect);
   }
-  if (LayerHandle maskLayer = common.maskLayer()) {
+  if (const LayerHandle& maskLayer = common.maskLayer()) {
     layer->SetMaskLayer(AsLayer(maskLayer));
   } else {
     layer->SetMaskLayer(nullptr);
   }
   layer->SetCompositorAnimations(common.compositorAnimations());
   // Clean up the Animations by id in the CompositorAnimationStorage
   // if there are no active animations on the layer
   if (mAnimStorage &&
--- a/js/src/vm/JSAtom.cpp
+++ b/js/src/vm/JSAtom.cpp
@@ -318,17 +318,17 @@ JSRuntime::transformToPermanentAtoms(JSC
     MOZ_ASSERT(!permanentAtoms);
     permanentAtoms = js_new<FrozenAtomSet>(atoms_);   // takes ownership of atoms_
 
     atoms_ = js_new<AtomSet>();
     if (!atoms_ || !atoms_->init(JS_STRING_HASH_COUNT))
         return false;
 
     for (FrozenAtomSet::Range r(permanentAtoms->all()); !r.empty(); r.popFront()) {
-        AtomStateEntry entry = r.front();
+        const AtomStateEntry& entry = r.front();
         JSAtom* atom = entry.asPtr(cx);
         atom->morphIntoPermanentAtom();
     }
 
     return true;
 }
 
 static inline AtomSet::Ptr
--- a/layout/base/nsCSSFrameConstructor.cpp
+++ b/layout/base/nsCSSFrameConstructor.cpp
@@ -11687,17 +11687,17 @@ nsCSSFrameConstructor::WrapFramesInFirst
     prevFrame = frame;
     frame = nextFrame;
   }
 }
 
 static nsIFrame*
 FindFirstLetterFrame(nsIFrame* aFrame, nsIFrame::ChildListID aListID)
 {
-  nsFrameList list = aFrame->GetChildList(aListID);
+  const nsFrameList& list = aFrame->GetChildList(aListID);
   for (nsFrameList::Enumerator e(list); !e.AtEnd(); e.Next()) {
     if (e.get()->IsLetterFrame()) {
       return e.get();
     }
   }
   return nullptr;
 }
 
--- a/layout/base/nsLayoutUtils.cpp
+++ b/layout/base/nsLayoutUtils.cpp
@@ -765,17 +765,17 @@ nsLayoutUtils::UnionChildOverflow(nsIFra
   FrameChildListIDs skip = aSkipChildLists |
       nsIFrame::kSelectPopupList | nsIFrame::kPopupList;
   for (nsIFrame::ChildListIterator childLists(aFrame);
        !childLists.IsDone(); childLists.Next()) {
     if (skip.Contains(childLists.CurrentID())) {
       continue;
     }
 
-    nsFrameList children = childLists.CurrentList();
+    const nsFrameList& children = childLists.CurrentList();
     for (nsFrameList::Enumerator e(children); !e.AtEnd(); e.Next()) {
       nsIFrame* child = e.get();
       nsOverflowAreas childOverflow =
         child->GetOverflowAreas() + child->GetPosition();
       aOverflowAreas.UnionWith(childOverflow);
     }
   }
 }
@@ -8054,17 +8054,17 @@ GetFontFacesForFramesInner(nsIFrame* aFr
                                          aFontFaces, aMaxRanges);
     }
     return;
   }
 
   nsIFrame::ChildListID childLists[] = { nsIFrame::kPrincipalList,
                                          nsIFrame::kPopupList };
   for (size_t i = 0; i < ArrayLength(childLists); ++i) {
-    nsFrameList children(aFrame->GetChildList(childLists[i]));
+    const nsFrameList& children(aFrame->GetChildList(childLists[i]));
     for (nsFrameList::Enumerator e(children); !e.AtEnd(); e.Next()) {
       nsIFrame* child = e.get();
       child = nsPlaceholderFrame::GetRealFrameFor(child);
       GetFontFacesForFramesInner(child, aFontFaces, aMaxRanges);
     }
   }
 }
 
--- a/layout/forms/nsButtonFrameRenderer.cpp
+++ b/layout/forms/nsButtonFrameRenderer.cpp
@@ -571,17 +571,17 @@ ImgDrawResult
 nsButtonFrameRenderer::PaintBorder(
   nsDisplayListBuilder* aBuilder,
   nsPresContext* aPresContext,
   gfxContext& aRenderingContext,
   const nsRect& aDirtyRect,
   const nsRect& aRect)
 {
   // get the button rect this is inside the focus and outline rects
-  nsRect buttonRect = aRect;
+  const nsRect& buttonRect = aRect;
   nsStyleContext* context = mFrame->StyleContext();
 
   PaintBorderFlags borderFlags = aBuilder->ShouldSyncDecodeImages()
                                ? PaintBorderFlags::SYNC_DECODE_IMAGES
                                : PaintBorderFlags();
 
   nsCSSRendering::PaintBoxShadowInner(aPresContext, aRenderingContext,
                                       mFrame, buttonRect);
--- a/layout/generic/nsFrame.cpp
+++ b/layout/generic/nsFrame.cpp
@@ -9308,17 +9308,17 @@ UnionBorderBoxes(nsIFrame* aFrame, bool 
   const nsIFrame::ChildListIDs skip(nsIFrame::kPopupList |
                                     nsIFrame::kSelectPopupList);
   for (nsIFrame::ChildListIterator childLists(aFrame);
        !childLists.IsDone(); childLists.Next()) {
     if (skip.Contains(childLists.CurrentID())) {
       continue;
     }
 
-    nsFrameList children = childLists.CurrentList();
+    const nsFrameList& children = childLists.CurrentList();
     for (nsFrameList::Enumerator e(children); !e.AtEnd(); e.Next()) {
       nsIFrame* child = e.get();
       // Note that passing |true| for aApplyTransform when
       // child->Combines3DTransformWithAncestors() is incorrect if our
       // aApplyTransform is false... but the opposite would be as
       // well.  This is because elements within a preserve-3d scene
       // are always transformed up to the top of the scene.  This
       // means we don't have a mechanism for getting a transform up to
--- a/layout/generic/nsGridContainerFrame.cpp
+++ b/layout/generic/nsGridContainerFrame.cpp
@@ -3783,17 +3783,17 @@ nsGridContainerFrame::Tracks::ResolveInt
   gfxContext* rc = &aState.mRenderingContext;
   if (sz.mState & TrackSize::eAutoMinSizing) {
     nscoord s;
     // Check if we need to apply "Automatic Minimum Size" and cache it.
     if (aGridItem.ShouldApplyAutoMinSize(wm, mAxis, aPercentageBasis)) {
       aGridItem.mState[mAxis] |= ItemState::eApplyAutoMinSize;
       // Clamp it if it's spanning a definite track max-sizing function.
       if (TrackSize::IsDefiniteMaxSizing(sz.mState)) {
-        auto maxCoord = aFunctions.MaxSizingFor(aRange.mStart);
+        const auto& maxCoord = aFunctions.MaxSizingFor(aRange.mStart);
         cache.mMinSizeClamp = maxCoord.ComputeCoordPercentCalc(aPercentageBasis);
         aGridItem.mState[mAxis] |= ItemState::eClampMarginBoxMinSize;
       }
       if (aConstraint != SizingConstraint::eMaxContent) {
         s = MinContentContribution(aGridItem, aState, rc, wm, mAxis, &cache);
       } else {
         s = MaxContentContribution(aGridItem, aState, rc, wm, mAxis, &cache);
       }
@@ -3821,17 +3821,17 @@ nsGridContainerFrame::Tracks::ResolveInt
     auto s = MaxContentContribution(aGridItem, aState, rc, wm, mAxis, &cache);
     if (sz.mLimit == NS_UNCONSTRAINEDSIZE) {
       sz.mLimit = s;
     } else {
       sz.mLimit = std::max(sz.mLimit, s);
     }
     if (MOZ_UNLIKELY(sz.mState & TrackSize::eFitContent)) {
       // Clamp mLimit to the fit-content() size, for ยง12.5.1.
-      auto maxCoord = aFunctions.MaxSizingFor(aRange.mStart);
+      const auto& maxCoord = aFunctions.MaxSizingFor(aRange.mStart);
       nscoord fitContentClamp =
         maxCoord.ComputeCoordPercentCalc(aPercentageBasis);
       sz.mLimit = std::min(sz.mLimit, fitContentClamp);
     }
   }
   if (sz.mLimit < sz.mBase) {
     sz.mLimit = sz.mBase;
   }
@@ -4221,17 +4221,17 @@ nsGridContainerFrame::Tracks::ResolveInt
         CachedIntrinsicSizes cache;
         // Calculate data for "Automatic Minimum Size" clamping, if needed.
         bool needed = ((state & TrackSize::eIntrinsicMinSizing) ||
                        aConstraint == SizingConstraint::eNoConstraint) &&
                       (gridItem.mState[mAxis] & ItemState::eApplyAutoMinSize);
         if (needed && TrackSize::IsDefiniteMaxSizing(state)) {
           nscoord minSizeClamp = 0;
           for (auto i = lineRange.mStart, end = lineRange.mEnd; i < end; ++i) {
-            auto maxCoord = aFunctions.MaxSizingFor(i);
+            const auto& maxCoord = aFunctions.MaxSizingFor(i);
             minSizeClamp += maxCoord.ComputeCoordPercentCalc(aPercentageBasis);
           }
           minSizeClamp += mGridGap * (span - 1);
           cache.mMinSizeClamp = minSizeClamp;
           gridItem.mState[mAxis] |= ItemState::eClampMarginBoxMinSize;
         }
         // Collect the various grid item size contributions we need.
         nscoord minSize = 0;
--- a/layout/generic/nsSimplePageSequenceFrame.cpp
+++ b/layout/generic/nsSimplePageSequenceFrame.cpp
@@ -444,17 +444,17 @@ void
 GetPrintCanvasElementsInFrame(nsIFrame* aFrame, nsTArray<RefPtr<HTMLCanvasElement> >* aArr)
 {
   if (!aFrame) {
     return;
   }
   for (nsIFrame::ChildListIterator childLists(aFrame);
     !childLists.IsDone(); childLists.Next()) {
 
-    nsFrameList children = childLists.CurrentList();
+    const nsFrameList& children = childLists.CurrentList();
     for (nsFrameList::Enumerator e(children); !e.AtEnd(); e.Next()) {
       nsIFrame* child = e.get();
 
       // Check if child is a nsHTMLCanvasFrame.
       nsHTMLCanvasFrame* canvasFrame = do_QueryFrame(child);
 
       // If there is a canvasFrame, try to get actual canvas element.
       if (canvasFrame) {
--- a/layout/painting/nsDisplayList.cpp
+++ b/layout/painting/nsDisplayList.cpp
@@ -3460,17 +3460,17 @@ nsDisplaySolidColorRegion::WriteDebugInf
 bool
 nsDisplaySolidColorRegion::CreateWebRenderCommands(mozilla::wr::DisplayListBuilder& aBuilder,
                                                    mozilla::wr::IpcResourceUpdateQueue& aResources,
                                                    const StackingContextHelper& aSc,
                                                    mozilla::layers::WebRenderLayerManager* aManager,
                                                    nsDisplayListBuilder* aDisplayListBuilder)
 {
   for (auto iter = mRegion.RectIter(); !iter.Done(); iter.Next()) {
-    nsRect rect = iter.Get();
+    const nsRect& rect = iter.Get();
     LayoutDeviceRect layerRects = LayoutDeviceRect::FromAppUnits(
       rect, mFrame->PresContext()->AppUnitsPerDevPixel());
     wr::LayoutRect transformedRect = aSc.ToRelativeLayoutRect(layerRects);
     aBuilder.PushRect(transformedRect,
                       transformedRect,
                       !BackfaceIsHidden(),
                       wr::ToColorF(ToDeviceColor(mColor)));
   }
@@ -5962,17 +5962,17 @@ nsDisplayBoxShadowOuter::CreateWebRender
 
       float blurRadius = float(shadow->mRadius) / float(appUnitsPerDevPixel);
       gfx::Color shadowColor = nsCSSRendering::GetShadowColor(shadow,
                                                               mFrame,
                                                               mOpacity);
 
       // We don't move the shadow rect here since WR does it for us
       // Now translate everything to device pixels.
-      nsRect shadowRect = frameRect;
+      const nsRect& shadowRect = frameRect;
       LayoutDevicePoint shadowOffset = LayoutDevicePoint::FromAppUnits(
           nsPoint(shadow->mXOffset, shadow->mYOffset),
           appUnitsPerDevPixel);
 
       LayoutDeviceRect deviceBox = LayoutDeviceRect::FromAppUnits(
           shadowRect, appUnitsPerDevPixel);
       wr::LayoutRect deviceBoxRect = aSc.ToRelativeLayoutRect(deviceBox);
       wr::LayoutRect deviceClipRect = aSc.ToRelativeLayoutRect(clipRect);
--- a/layout/svg/nsSVGPatternFrame.cpp
+++ b/layout/svg/nsSVGPatternFrame.cpp
@@ -676,17 +676,17 @@ nsSVGPatternFrame::ConstructCTM(const ns
       ctx = static_cast<nsSVGElement*>(targetContent)->GetCtx();
     }
     scaleX = scaleY = MaxExpansion(callerCTM);
   }
 
   if (!aViewBox.IsExplicitlySet()) {
     return gfxMatrix(scaleX, 0.0, 0.0, scaleY, 0.0, 0.0);
   }
-  const nsSVGViewBoxRect viewBoxRect = aViewBox.GetAnimValue();
+  const nsSVGViewBoxRect& viewBoxRect = aViewBox.GetAnimValue();
 
   if (viewBoxRect.height <= 0.0f || viewBoxRect.width <= 0.0f) {
     return gfxMatrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0); // singular
   }
 
   float viewportWidth, viewportHeight;
   if (targetContent->IsSVGElement()) {
     // If we're dealing with an SVG target only retrieve the context once.
--- a/toolkit/components/extensions/WebExtensionPolicy.cpp
+++ b/toolkit/components/extensions/WebExtensionPolicy.cpp
@@ -398,17 +398,17 @@ WebExtensionContentScript::Matches(const
   }
 
   // Content scripts are not allowed on pages that have elevated
   // privileges via mozAddonManager (see bug 1280234)
   if (AddonManagerWebAPI::IsValidSite(aDoc.PrincipalURL().URI())) {
     return false;
   }
 
-  URLInfo urlinfo(aDoc.PrincipalURL());
+  const URLInfo& urlinfo(aDoc.PrincipalURL());
   if (mHasActiveTabPermission && aDoc.ShouldMatchActiveTabPermission() &&
       MatchPattern::MatchesAllURLs(urlinfo)) {
     return true;
   }
 
   return MatchesURI(urlinfo);
 }
 
--- a/toolkit/components/url-classifier/ProtocolParser.cpp
+++ b/toolkit/components/url-classifier/ProtocolParser.cpp
@@ -774,17 +774,17 @@ ProtocolParserProtobuf::End()
     return;
   }
 
   auto minWaitDuration = response.minimum_wait_duration();
   mUpdateWaitSec = minWaitDuration.seconds() +
                    minWaitDuration.nanos() / 1000000000;
 
   for (int i = 0; i < response.list_update_responses_size(); i++) {
-    auto r = response.list_update_responses(i);
+    const auto& r = response.list_update_responses(i);
     nsresult rv = ProcessOneResponse(r);
     if (NS_SUCCEEDED(rv)) {
       mUpdateStatus = rv;
     } else {
       nsAutoCString errorName;
       mozilla::GetErrorName(rv, errorName);
       NS_WARNING(nsPrintfCString("Failed to process one response: %s",
                                  errorName.get()).get());
@@ -882,17 +882,17 @@ ProtocolParserProtobuf::ProcessOneRespon
 nsresult
 ProtocolParserProtobuf::ProcessAdditionOrRemoval(TableUpdateV4& aTableUpdate,
                                                  const ThreatEntrySetList& aUpdate,
                                                  bool aIsAddition)
 {
   nsresult ret = NS_OK;
 
   for (int i = 0; i < aUpdate.size(); i++) {
-    auto update = aUpdate.Get(i);
+    const auto& update = aUpdate.Get(i);
     if (!update.has_compression_type()) {
       NS_WARNING(nsPrintfCString("%s with no compression type.",
                                   aIsAddition ? "Addition" : "Removal").get());
       continue;
     }
 
     switch (update.compression_type()) {
     case COMPRESSION_TYPE_UNSPECIFIED:
--- a/uriloader/exthandler/ContentHandlerService.cpp
+++ b/uriloader/exthandler/ContentHandlerService.cpp
@@ -126,17 +126,17 @@ NS_IMETHODIMP RemoteHandlerApp::LaunchWi
 {
   return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 NS_IMPL_ISUPPORTS(RemoteHandlerApp, nsIHandlerApp)
 
 static inline void CopyHanderInfoTonsIHandlerInfo(const HandlerInfo& info, nsIHandlerInfo* aHandlerInfo)
 {
-  HandlerApp preferredApplicationHandler = info.preferredApplicationHandler();
+  const HandlerApp& preferredApplicationHandler = info.preferredApplicationHandler();
   nsCOMPtr<nsIHandlerApp> preferredApp(new RemoteHandlerApp(preferredApplicationHandler));
   aHandlerInfo->SetPreferredApplicationHandler(preferredApp);
   nsCOMPtr<nsIMutableArray> possibleHandlers;
   aHandlerInfo->GetPossibleApplicationHandlers(getter_AddRefs(possibleHandlers));
   possibleHandlers->AppendElement(preferredApp);
 
   if (info.isMIMEInfo()) {
     const auto& fileExtensions = info.extensions();
--- a/widget/nsClipboardProxy.cpp
+++ b/widget/nsClipboardProxy.cpp
@@ -82,17 +82,17 @@ nsClipboardProxy::GetData(nsITransferabl
       rv = dataWrapper->SetData(data);
       NS_ENSURE_SUCCESS(rv, rv);
 
       rv = aTransferable->SetTransferData(item.flavor().get(), dataWrapper,
                                           data.Length() * sizeof(char16_t));
       NS_ENSURE_SUCCESS(rv, rv);
     } else if (item.data().type() == IPCDataTransferData::TShmem) {
       // If this is an image, convert it into an nsIInputStream.
-      nsCString flavor = item.flavor();
+      const nsCString& flavor = item.flavor();
       mozilla::ipc::Shmem data = item.data().get_Shmem();
       if (flavor.EqualsLiteral(kJPEGImageMime) ||
           flavor.EqualsLiteral(kJPGImageMime) ||
           flavor.EqualsLiteral(kPNGImageMime) ||
           flavor.EqualsLiteral(kGIFImageMime)) {
         nsCOMPtr<nsIInputStream> stream;
 
         NS_NewCStringInputStream(getter_AddRefs(stream),