Bug 1542646 Part 12 - avoid implicit double to float conversions by using std:: variants of mathematical functions r=dholbert
authorlongsonr <longsonr@gmail.com>
Thu, 25 Apr 2019 22:46:33 +0100
changeset 530249 12a4b6b72645f2327adb531d42ce31f39a5ea3f9
parent 530248 63fcd49131d7303b868a34241024d4a72ed1aafc
child 530250 5279ac14ae4898b1d2d771f14891b395b068626a
push id11265
push userffxbld-merge
push dateMon, 13 May 2019 10:53:39 +0000
treeherdermozilla-beta@77e0fe8dbdd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdholbert
bugs1542646
milestone68.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 1542646 Part 12 - avoid implicit double to float conversions by using std:: variants of mathematical functions r=dholbert
dom/svg/SVGContentUtils.cpp
dom/svg/SVGLineElement.cpp
dom/svg/SVGMotionSMILType.cpp
dom/svg/SVGPathSegUtils.cpp
dom/svg/SVGPolyElement.cpp
dom/svg/SVGPolygonElement.cpp
dom/svg/SVGTransformListSMILType.cpp
dom/svg/SVGViewBoxSMILType.cpp
layout/svg/nsSVGGradientFrame.cpp
--- a/dom/svg/SVGContentUtils.cpp
+++ b/dom/svg/SVGContentUtils.cpp
@@ -581,17 +581,17 @@ void SVGContentUtils::RectilinearGetStro
 }
 
 double SVGContentUtils::ComputeNormalizedHypotenuse(double aWidth,
                                                     double aHeight) {
   return NS_hypot(aWidth, aHeight) / M_SQRT2;
 }
 
 float SVGContentUtils::AngleBisect(float a1, float a2) {
-  float delta = fmod(a2 - a1, static_cast<float>(2 * M_PI));
+  float delta = std::fmod(a2 - a1, static_cast<float>(2 * M_PI));
   if (delta < 0) {
     delta += static_cast<float>(2 * M_PI);
   }
   /* delta is now the angle from a1 around to a2, in the range [0, 2*M_PI) */
   float r = a1 + delta / 2;
   if (delta >= M_PI) {
     /* the arc from a2 to a1 is smaller, so use the ray on that side */
     r += static_cast<float>(M_PI);
--- a/dom/svg/SVGLineElement.cpp
+++ b/dom/svg/SVGLineElement.cpp
@@ -99,17 +99,17 @@ SVGElement::LengthAttributesInfo SVGLine
 //----------------------------------------------------------------------
 // SVGGeometryElement methods
 
 void SVGLineElement::GetMarkPoints(nsTArray<SVGMark>* aMarks) {
   float x1, y1, x2, y2;
 
   GetAnimatedLengthValues(&x1, &y1, &x2, &y2, nullptr);
 
-  float angle = atan2(y2 - y1, x2 - x1);
+  float angle = std::atan2(y2 - y1, x2 - x1);
 
   aMarks->AppendElement(SVGMark(x1, y1, angle, SVGMark::eStart));
   aMarks->AppendElement(SVGMark(x2, y2, angle, SVGMark::eEnd));
 }
 
 void SVGLineElement::GetAsSimplePath(SimplePath* aSimplePath) {
   float x1, y1, x2, y2;
   GetAnimatedLengthValues(&x1, &y1, &x2, &y2, nullptr);
--- a/dom/svg/SVGMotionSMILType.cpp
+++ b/dom/svg/SVGMotionSMILType.cpp
@@ -324,17 +324,17 @@ nsresult SVGMotionSMILType::ComputeDista
 
   MOZ_ASSERT(from.mSegmentType == to.mSegmentType,
              "Mismatched MotionSegment types");
   if (from.mSegmentType == eSegmentType_PathPoint) {
     const PathPointParams& fromParams = from.mU.mPathPointParams;
     const PathPointParams& toParams = to.mU.mPathPointParams;
     MOZ_ASSERT(fromParams.mPath == toParams.mPath,
                "Interpolation endpoints should be from same path");
-    aDistance = fabs(toParams.mDistToPoint - fromParams.mDistToPoint);
+    aDistance = std::fabs(toParams.mDistToPoint - fromParams.mDistToPoint);
   } else {
     const TranslationParams& fromParams = from.mU.mTranslationParams;
     const TranslationParams& toParams = to.mU.mTranslationParams;
     float dX = toParams.mX - fromParams.mX;
     float dY = toParams.mY - fromParams.mY;
     aDistance = NS_hypot(dX, dY);
   }
 
--- a/dom/svg/SVGPathSegUtils.cpp
+++ b/dom/svg/SVGPathSegUtils.cpp
@@ -190,46 +190,46 @@ static void TraverseLinetoRel(const floa
   }
   aState.pos = to;
 }
 
 static void TraverseLinetoHorizontalAbs(const float* aArgs,
                                         SVGPathTraversalState& aState) {
   Point to(aArgs[0], aState.pos.y);
   if (aState.ShouldUpdateLengthAndControlPoints()) {
-    aState.length += fabs(to.x - aState.pos.x);
+    aState.length += std::fabs(to.x - aState.pos.x);
     aState.cp1 = aState.cp2 = to;
   }
   aState.pos = to;
 }
 
 static void TraverseLinetoHorizontalRel(const float* aArgs,
                                         SVGPathTraversalState& aState) {
   aState.pos.x += aArgs[0];
   if (aState.ShouldUpdateLengthAndControlPoints()) {
-    aState.length += fabs(aArgs[0]);
+    aState.length += std::fabs(aArgs[0]);
     aState.cp1 = aState.cp2 = aState.pos;
   }
 }
 
 static void TraverseLinetoVerticalAbs(const float* aArgs,
                                       SVGPathTraversalState& aState) {
   Point to(aState.pos.x, aArgs[0]);
   if (aState.ShouldUpdateLengthAndControlPoints()) {
-    aState.length += fabs(to.y - aState.pos.y);
+    aState.length += std::fabs(to.y - aState.pos.y);
     aState.cp1 = aState.cp2 = to;
   }
   aState.pos = to;
 }
 
 static void TraverseLinetoVerticalRel(const float* aArgs,
                                       SVGPathTraversalState& aState) {
   aState.pos.y += aArgs[0];
   if (aState.ShouldUpdateLengthAndControlPoints()) {
-    aState.length += fabs(aArgs[0]);
+    aState.length += std::fabs(aArgs[0]);
     aState.cp1 = aState.cp2 = aState.pos;
   }
 }
 
 static void TraverseCurvetoCubicAbs(const float* aArgs,
                                     SVGPathTraversalState& aState) {
   Point to(aArgs[4], aArgs[5]);
   if (aState.ShouldUpdateLengthAndControlPoints()) {
--- a/dom/svg/SVGPolyElement.cpp
+++ b/dom/svg/SVGPolyElement.cpp
@@ -68,17 +68,17 @@ void SVGPolyElement::GetMarkPoints(nsTAr
 
   float px = points[0].mX, py = points[0].mY, prevAngle = 0.0;
 
   aMarks->AppendElement(SVGMark(px, py, 0, SVGMark::eStart));
 
   for (uint32_t i = 1; i < points.Length(); ++i) {
     float x = points[i].mX;
     float y = points[i].mY;
-    float angle = atan2(y - py, x - px);
+    float angle = std::atan2(y - py, x - px);
 
     // Vertex marker.
     if (i == 1) {
       aMarks->ElementAt(0).angle = angle;
     } else {
       aMarks->ElementAt(aMarks->Length() - 1).angle =
           SVGContentUtils::AngleBisect(prevAngle, angle);
     }
--- a/dom/svg/SVGPolygonElement.cpp
+++ b/dom/svg/SVGPolygonElement.cpp
@@ -41,17 +41,18 @@ void SVGPolygonElement::GetMarkPoints(ns
   SVGPolyElement::GetMarkPoints(aMarks);
 
   if (aMarks->IsEmpty() || aMarks->LastElement().type != SVGMark::eEnd) {
     return;
   }
 
   SVGMark *endMark = &aMarks->LastElement();
   SVGMark *startMark = &aMarks->ElementAt(0);
-  float angle = atan2(startMark->y - endMark->y, startMark->x - endMark->x);
+  float angle =
+      std::atan2(startMark->y - endMark->y, startMark->x - endMark->x);
 
   endMark->type = SVGMark::eMid;
   endMark->angle = SVGContentUtils::AngleBisect(angle, endMark->angle);
   startMark->angle = SVGContentUtils::AngleBisect(angle, startMark->angle);
   // for a polygon (as opposed to a polyline) there's an implicit extra point
   // co-located with the start point that SVGPolyElement::GetMarkPoints
   // doesn't return
   aMarks->AppendElement(
--- a/dom/svg/SVGTransformListSMILType.cpp
+++ b/dom/svg/SVGTransformListSMILType.cpp
@@ -202,17 +202,17 @@ nsresult SVGTransformListSMILType::Compu
       aDistance = sqrt(pow(a_tx - b_tx, 2) + (pow(a_ty - b_ty, 2)));
     } break;
 
     case SVG_TRANSFORM_ROTATE:
     case SVG_TRANSFORM_SKEWX:
     case SVG_TRANSFORM_SKEWY: {
       const float& a = fromTransform.mParams[0];
       const float& b = toTransform.mParams[0];
-      aDistance = fabs(a - b);
+      aDistance = std::fabs(a - b);
     } break;
 
     default:
       NS_ERROR("Got bad transform types for calculating distances");
       aDistance = 1.0;
       return NS_ERROR_FAILURE;
   }
 
--- a/dom/svg/SVGViewBoxSMILType.cpp
+++ b/dom/svg/SVGViewBoxSMILType.cpp
@@ -82,18 +82,18 @@ nsresult SVGViewBoxSMILType::ComputeDist
   // given change in the left side as it is for an equal change in the opposite
   // side. See https://bugzilla.mozilla.org/show_bug.cgi?id=541884#c12
 
   float dLeft = to->x - from->x;
   float dTop = to->y - from->y;
   float dRight = (to->x + to->width) - (from->x + from->width);
   float dBottom = (to->y + to->height) - (from->y + from->height);
 
-  aDistance =
-      sqrt(dLeft * dLeft + dTop * dTop + dRight * dRight + dBottom * dBottom);
+  aDistance = std::sqrt(dLeft * dLeft + dTop * dTop + dRight * dRight +
+                        dBottom * dBottom);
 
   return NS_OK;
 }
 
 nsresult SVGViewBoxSMILType::Interpolate(const SMILValue& aStartVal,
                                          const SMILValue& aEndVal,
                                          double aUnitDistance,
                                          SMILValue& aResult) const {
--- a/layout/svg/nsSVGGradientFrame.cpp
+++ b/layout/svg/nsSVGGradientFrame.cpp
@@ -572,23 +572,23 @@ already_AddRefed<gfxPattern> nsSVGRadial
     // The focal point (fFx and fFy) must be clamped to be *inside* - not on -
     // the circumference of the gradient or we'll get rendering anomalies. We
     // calculate the distance from the focal point to the gradient center and
     // make sure it is *less* than the gradient radius.
     // 1/128 is the limit of the fractional part of cairo's 24.8 fixed point
     // representation divided by 2 to ensure that we get different cairo
     // fractions
     double dMax = std::max(0.0, r - 1.0 / 128);
-    float dx = fx - cx;
-    float dy = fy - cy;
-    double d = sqrt((dx * dx) + (dy * dy));
+    double dx = fx - cx;
+    double dy = fy - cy;
+    double d = std::sqrt((dx * dx) + (dy * dy));
     if (d > dMax) {
-      double angle = atan2(dy, dx);
-      fx = (float)(dMax * cos(angle)) + cx;
-      fy = (float)(dMax * sin(angle)) + cy;
+      double angle = std::atan2(dy, dx);
+      fx = float(dMax * std::cos(angle)) + cx;
+      fy = float(dMax * std::sin(angle)) + cy;
     }
   }
 
   RefPtr<gfxPattern> pattern = new gfxPattern(fx, fy, fr, cx, cy, r);
   return pattern.forget();
 }
 
 // -------------------------------------------------------------------------