Bug 1390088 - Part 3. Declare some locale nsSVGLength2 references as const in nsSVGOuterSVGFrame.cpp. draft
authorcku <cku@mozilla.com>
Mon, 21 Aug 2017 16:25:24 +0800
changeset 651833 362efefd9aa9e184c28133149bf8adbe4b9a33cd
parent 651832 a4f4e267367c49df60bf729b7f9b977cc28d4819
child 727874 cd5a15c471795db4407cfeb8977c59f27163692a
push id75821
push userbmo:cku@mozilla.com
push dateThu, 24 Aug 2017 02:20:38 +0000
bugs1390088
milestone57.0a1
Bug 1390088 - Part 3. Declare some locale nsSVGLength2 references as const in nsSVGOuterSVGFrame.cpp. This patch has no direct relation with this bug. When tracing the code, I noticed those local nsSVGLength2 variables can be declared as const reference. MozReview-Commit-ID: 6gkdlpv8W7H
layout/svg/nsSVGOuterSVGFrame.cpp
--- a/layout/svg/nsSVGOuterSVGFrame.cpp
+++ b/layout/svg/nsSVGOuterSVGFrame.cpp
@@ -208,18 +208,20 @@ nsSVGOuterSVGFrame::GetPrefISize(gfxCont
 nsSVGOuterSVGFrame::GetIntrinsicSize()
 {
   // XXXjwatt Note that here we want to return the CSS width/height if they're
   // specified and we're embedded inside an nsIObjectLoadingContent.
 
   IntrinsicSize intrinsicSize;
 
   SVGSVGElement *content = static_cast<SVGSVGElement*>(mContent);
-  nsSVGLength2 &width  = content->mLengthAttributes[SVGSVGElement::ATTR_WIDTH];
-  nsSVGLength2 &height = content->mLengthAttributes[SVGSVGElement::ATTR_HEIGHT];
+  const nsSVGLength2& width =
+    content->mLengthAttributes[SVGSVGElement::ATTR_WIDTH];
+  const nsSVGLength2& height =
+    content->mLengthAttributes[SVGSVGElement::ATTR_HEIGHT];
 
   if (!width.IsPercentage()) {
     nscoord val = nsPresContext::CSSPixelsToAppUnits(width.GetAnimValue(content));
     if (val < 0) val = 0;
     intrinsicSize.width.SetCoordValue(val);
   }
 
   if (!height.IsPercentage()) {
@@ -234,18 +236,20 @@ nsSVGOuterSVGFrame::GetIntrinsicSize()
 /* virtual */ nsSize
 nsSVGOuterSVGFrame::GetIntrinsicRatio()
 {
   // We only have an intrinsic size/ratio if our width and height attributes
   // are both specified and set to non-percentage values, or we have a viewBox
   // rect: http://www.w3.org/TR/SVGMobile12/coords.html#IntrinsicSizing
 
   SVGSVGElement *content = static_cast<SVGSVGElement*>(mContent);
-  nsSVGLength2 &width  = content->mLengthAttributes[SVGSVGElement::ATTR_WIDTH];
-  nsSVGLength2 &height = content->mLengthAttributes[SVGSVGElement::ATTR_HEIGHT];
+  const nsSVGLength2& width =
+    content->mLengthAttributes[SVGSVGElement::ATTR_WIDTH];
+  const nsSVGLength2& height =
+    content->mLengthAttributes[SVGSVGElement::ATTR_HEIGHT];
 
   if (!width.IsPercentage() && !height.IsPercentage()) {
     nsSize ratio(NSToCoordRoundWithClamp(width.GetAnimValue(content)),
                  NSToCoordRoundWithClamp(height.GetAnimValue(content)));
     if (ratio.width < 0) {
       ratio.width = 0;
     }
     if (ratio.height < 0) {
@@ -317,27 +321,27 @@ nsSVGOuterSVGFrame::ComputeSize(gfxConte
     // We also need to honour the width and height attributes' default values
     // of 100% when we're the root of a browsing context.  (GetIntrinsicSize()
     // doesn't report these since there's no such thing as a percentage
     // intrinsic size.  Also note that explicit percentage values are mapped
     // into style, so the following isn't for them.)
 
     SVGSVGElement* content = static_cast<SVGSVGElement*>(mContent);
 
-    nsSVGLength2 &width =
+    const nsSVGLength2& width =
       content->mLengthAttributes[SVGSVGElement::ATTR_WIDTH];
     if (width.IsPercentage()) {
       MOZ_ASSERT(intrinsicSize.width.GetUnit() == eStyleUnit_None,
                  "GetIntrinsicSize should have reported no intrinsic width");
       float val = width.GetAnimValInSpecifiedUnits() / 100.0f;
       if (val < 0.0f) val = 0.0f;
       intrinsicSize.width.SetCoordValue(val * cbSize.Width(aWM));
     }
 
-    nsSVGLength2 &height =
+    const nsSVGLength2& height =
       content->mLengthAttributes[SVGSVGElement::ATTR_HEIGHT];
     NS_ASSERTION(aCBSize.BSize(aWM) != NS_AUTOHEIGHT,
                  "root should not have auto-height containing block");
     if (height.IsPercentage()) {
       MOZ_ASSERT(intrinsicSize.height.GetUnit() == eStyleUnit_None,
                  "GetIntrinsicSize should have reported no intrinsic height");
       float val = height.GetAnimValInSpecifiedUnits() / 100.0f;
       if (val < 0.0f) val = 0.0f;
@@ -958,18 +962,18 @@ nsSVGOuterSVGFrame::IsRootOfImage()
   }
 
   return false;
 }
 
 bool
 nsSVGOuterSVGFrame::VerticalScrollbarNotNeeded() const
 {
-  nsSVGLength2 &height = static_cast<SVGSVGElement*>(mContent)->
-                           mLengthAttributes[SVGSVGElement::ATTR_HEIGHT];
+  const nsSVGLength2& height = static_cast<SVGSVGElement*>(mContent)->
+                                 mLengthAttributes[SVGSVGElement::ATTR_HEIGHT];
   return height.IsPercentage() && height.GetBaseValInSpecifiedUnits() <= 100;
 }
 
 void
 nsSVGOuterSVGFrame::AppendDirectlyOwnedAnonBoxes(nsTArray<OwnedAnonBox>& aResult)
 {
   nsIFrame* anonKid = PrincipalChildList().FirstChild();
   MOZ_ASSERT(anonKid->IsSVGOuterSVGAnonChildFrame());