Bug 847480 - Convert DeprecatedAbs overloads taking floating point (except for nscoord uses, when nscoord is optionally a floating point type) to Abs. r=Ms2ger
authorJeff Walden <jwalden@mit.edu>
Tue, 05 Mar 2013 15:43:44 -0800
changeset 135109 1338c63a370bb2c030b73276a72eedc835eceb01
parent 135108 eb393a9ef207cc8de47d100bdc2ef7ed5a42dfd0
child 135110 0780edf29bf1eae5143159433904db306c8c859d
push id2452
push userlsblakk@mozilla.com
push dateMon, 13 May 2013 16:59:38 +0000
treeherdermozilla-beta@d4b152d29d8d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMs2ger
bugs847480
milestone22.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 847480 - Convert DeprecatedAbs overloads taking floating point (except for nscoord uses, when nscoord is optionally a floating point type) to Abs. r=Ms2ger
content/events/src/nsEventStateManager.cpp
content/html/content/src/nsHTMLMediaElement.cpp
content/media/MediaDecoder.cpp
gfx/thebes/gfxFont.cpp
js/src/jsmath.cpp
js/src/prmjtime.cpp
js/src/vm/DateTime.h
layout/base/nsCSSRendering.cpp
layout/generic/nsTextFrameThebes.cpp
layout/style/nsStyleAnimation.cpp
mfbt/MathAlgorithms.h
--- a/content/events/src/nsEventStateManager.cpp
+++ b/content/events/src/nsEventStateManager.cpp
@@ -5585,18 +5585,18 @@ nsEventStateManager::WheelPrefs::CancelA
 
 nsEventStateManager::WheelPrefs::Action
 nsEventStateManager::WheelPrefs::ComputeActionFor(widget::WheelEvent* aEvent)
 {
   Index index = GetIndexFor(aEvent);
   Init(index);
 
   bool deltaXPreferred =
-    (DeprecatedAbs(aEvent->deltaX) > DeprecatedAbs(aEvent->deltaY) &&
-     DeprecatedAbs(aEvent->deltaX) > DeprecatedAbs(aEvent->deltaZ));
+    (Abs(aEvent->deltaX) > Abs(aEvent->deltaY) &&
+     Abs(aEvent->deltaX) > Abs(aEvent->deltaZ));
   Action* actions = deltaXPreferred ? mOverriddenActionsX : mActions;
   if (actions[index] == ACTION_NONE || actions[index] == ACTION_SCROLL) {
     return actions[index];
   }
 
   // Momentum events shouldn't run special actions.
   if (aEvent->isMomentum) {
     // Use the default action.  Note that user might kill the wheel scrolling.
@@ -5620,21 +5620,21 @@ nsEventStateManager::WheelPrefs::NeedToC
 }
 
 bool
 nsEventStateManager::WheelPrefs::IsOverOnePageScrollAllowedX(
                                    widget::WheelEvent* aEvent)
 {
   Index index = GetIndexFor(aEvent);
   Init(index);
-  return DeprecatedAbs(mMultiplierX[index]) >=
+  return Abs(mMultiplierX[index]) >=
            MIN_MULTIPLIER_VALUE_ALLOWING_OVER_ONE_PAGE_SCROLL;
 }
 
 bool
 nsEventStateManager::WheelPrefs::IsOverOnePageScrollAllowedY(
                                    widget::WheelEvent* aEvent)
 {
   Index index = GetIndexFor(aEvent);
   Init(index);
-  return DeprecatedAbs(mMultiplierY[index]) >=
+  return Abs(mMultiplierY[index]) >=
            MIN_MULTIPLIER_VALUE_ALLOWING_OVER_ONE_PAGE_SCROLL;
 }
--- a/content/html/content/src/nsHTMLMediaElement.cpp
+++ b/content/html/content/src/nsHTMLMediaElement.cpp
@@ -3377,20 +3377,20 @@ void nsHTMLMediaElement::NotifyAudioAvai
   }
 }
 
 static double ClampPlaybackRate(double aPlaybackRate)
 {
   if (aPlaybackRate == 0.0) {
     return aPlaybackRate;
   }
-  if (DeprecatedAbs(aPlaybackRate) < MIN_PLAYBACKRATE) {
+  if (Abs(aPlaybackRate) < MIN_PLAYBACKRATE) {
     return aPlaybackRate < 0 ? -MIN_PLAYBACKRATE : MIN_PLAYBACKRATE;
   }
-  if (DeprecatedAbs(aPlaybackRate) > MAX_PLAYBACKRATE) {
+  if (Abs(aPlaybackRate) > MAX_PLAYBACKRATE) {
     return aPlaybackRate < 0 ? -MAX_PLAYBACKRATE : MAX_PLAYBACKRATE;
   }
   return aPlaybackRate;
 }
 
 /* attribute double defaultPlaybackRate; */
 NS_IMETHODIMP nsHTMLMediaElement::GetDefaultPlaybackRate(double* aDefaultPlaybackRate)
 {
--- a/content/media/MediaDecoder.cpp
+++ b/content/media/MediaDecoder.cpp
@@ -589,21 +589,21 @@ nsresult MediaDecoder::Seek(double aTime
       // |range + 1| can't be negative, because the only possible negative value
       // for |range| is -1.
       if (uint32_t(range + 1) < length) {
         double leftBound, rightBound;
         res = seekable.End(range, &leftBound);
         NS_ENSURE_SUCCESS(res, NS_OK);
         res = seekable.Start(range + 1, &rightBound);
         NS_ENSURE_SUCCESS(res, NS_OK);
-        double distanceLeft = DeprecatedAbs(leftBound - aTime);
-        double distanceRight = DeprecatedAbs(rightBound - aTime);
+        double distanceLeft = Abs(leftBound - aTime);
+        double distanceRight = Abs(rightBound - aTime);
         if (distanceLeft == distanceRight) {
-          distanceLeft = DeprecatedAbs(leftBound - mCurrentTime);
-          distanceRight = DeprecatedAbs(rightBound - mCurrentTime);
+          distanceLeft = Abs(leftBound - mCurrentTime);
+          distanceRight = Abs(rightBound - mCurrentTime);
         } 
         aTime = (distanceLeft < distanceRight) ? leftBound : rightBound;
       } else {
         // Seek target is after the end last range in seekable data.
         // Clamp the seek target to the end of the last seekable range.
         res = seekable.End(length - 1, &aTime);
         NS_ENSURE_SUCCESS(res, NS_OK);
       }
--- a/gfx/thebes/gfxFont.cpp
+++ b/gfx/thebes/gfxFont.cpp
@@ -2961,18 +2961,18 @@ gfxFont::InitMetricsFromSfntTables(Metri
     if (NS_SUCCEEDED(mFontEntry->GetFontTable(kOS_2TableTag, os2data))) {
         OS2Table *os2 = reinterpret_cast<OS2Table*>(os2data.Elements());
 
         if (os2data.Length() >= offsetof(OS2Table, sxHeight) +
                                 sizeof(int16_t) &&
             uint16_t(os2->version) >= 2) {
             // version 2 and later includes the x-height field
             SET_SIGNED(xHeight, os2->sxHeight);
-            // DeprecatedAbs because of negative xHeight seen in Kokonor (Tibetan) font
-            aMetrics.xHeight = DeprecatedAbs(aMetrics.xHeight);
+            // Abs because of negative xHeight seen in Kokonor (Tibetan) font
+            aMetrics.xHeight = Abs(aMetrics.xHeight);
         }
         // this should always be present
         if (os2data.Length() >= offsetof(OS2Table, yStrikeoutPosition) +
                                 sizeof(int16_t)) {
             SET_SIGNED(aveCharWidth, os2->xAvgCharWidth);
             SET_SIGNED(subscriptOffset, os2->ySubscriptYOffset);
             SET_SIGNED(superscriptOffset, os2->ySuperscriptYOffset);
             SET_SIGNED(strikeoutSize, os2->yStrikeoutSize);
--- a/js/src/jsmath.cpp
+++ b/js/src/jsmath.cpp
@@ -26,17 +26,17 @@
 #include "jslibmath.h"
 #include "jscompartment.h"
 
 #include "jsinferinlines.h"
 #include "jsobjinlines.h"
 
 using namespace js;
 
-using mozilla::DeprecatedAbs;
+using mozilla::Abs;
 
 #ifndef M_E
 #define M_E             2.7182818284590452354
 #endif
 #ifndef M_LOG2E
 #define M_LOG2E         1.4426950408889634074
 #endif
 #ifndef M_LOG10E
@@ -100,17 +100,17 @@ js_math_abs(JSContext *cx, unsigned argc
     double x, z;
 
     if (argc == 0) {
         vp->setDouble(js_NaN);
         return JS_TRUE;
     }
     if (!ToNumber(cx, vp[2], &x))
         return JS_FALSE;
-    z = DeprecatedAbs(x);
+    z = Abs(x);
     vp->setNumber(z);
     return JS_TRUE;
 }
 
 double
 js::math_acos_impl(MathCache *cache, double x)
 {
 #if defined(SOLARIS) && defined(__GNUC__)
--- a/js/src/prmjtime.cpp
+++ b/js/src/prmjtime.cpp
@@ -353,17 +353,17 @@ PRMJ_Now(void)
             /* Check for clock skew */
             diff = lowresTime - highresTime;
 
             /* For some reason that I have not determined, the skew can be
                up to twice a kernel tick. This does not seem to happen by
                itself, but I have only seen it triggered by another program
                doing some kind of file I/O. The symptoms are a negative diff
                followed by an equally large positive diff. */
-            if (mozilla::DeprecatedAbs(diff) > 2 * skewThreshold) {
+            if (mozilla::Abs(diff) > 2 * skewThreshold) {
                 /*fprintf(stderr,"Clock skew detected (diff = %f)!\n", diff);*/
 
                 if (calibrated) {
                     /* If we already calibrated once this instance, and the
                        clock is still skewed, then either the processor(s) are
                        wildly changing clockspeed or the system is so busy that
                        we get switched out for long periods of time. In either
                        case, it would be infeasible to make use of high
--- a/js/src/vm/DateTime.h
+++ b/js/src/vm/DateTime.h
@@ -37,17 +37,17 @@ const double msPerDay = msPerHour * Hour
 const unsigned SecondsPerHour = 60 * 60;
 const unsigned SecondsPerDay = SecondsPerHour * 24;
 
 /* ES5 15.9.1.14. */
 inline double
 TimeClip(double time)
 {
     /* Steps 1-2. */
-    if (!MOZ_DOUBLE_IS_FINITE(time) || mozilla::DeprecatedAbs(time) > 8.64e15)
+    if (!MOZ_DOUBLE_IS_FINITE(time) || mozilla::Abs(time) > 8.64e15)
         return js_NaN;
 
     /* Step 3. */
     return ToInteger(time + (+0.0));
 }
 
 /*
  * Stores date/time information, particularly concerning the current local
--- a/layout/base/nsCSSRendering.cpp
+++ b/layout/base/nsCSSRendering.cpp
@@ -1979,20 +1979,20 @@ ComputeRadialGradientLine(nsPresContext*
       ConvertGradientValueToPixels(aGradient->mBgPosX, aBoxSize.width,
                                    appUnitsPerPixel),
       ConvertGradientValueToPixels(aGradient->mBgPosY, aBoxSize.height,
                                    appUnitsPerPixel));
   }
 
   // Compute gradient shape: the x and y radii of an ellipse.
   double radiusX, radiusY;
-  double leftDistance = DeprecatedAbs(aLineStart->x);
-  double rightDistance = DeprecatedAbs(aBoxSize.width - aLineStart->x);
-  double topDistance = DeprecatedAbs(aLineStart->y);
-  double bottomDistance = DeprecatedAbs(aBoxSize.height - aLineStart->y);
+  double leftDistance = Abs(aLineStart->x);
+  double rightDistance = Abs(aBoxSize.width - aLineStart->x);
+  double topDistance = Abs(aLineStart->y);
+  double bottomDistance = Abs(aBoxSize.height - aLineStart->y);
   switch (aGradient->mSize) {
   case NS_STYLE_GRADIENT_SIZE_CLOSEST_SIDE:
     radiusX = std::min(leftDistance, rightDistance);
     radiusY = std::min(topDistance, bottomDistance);
     if (aGradient->mShape == NS_STYLE_GRADIENT_SHAPE_CIRCULAR) {
       radiusX = radiusY = std::min(radiusX, radiusY);
     }
     break;
--- a/layout/generic/nsTextFrameThebes.cpp
+++ b/layout/generic/nsTextFrameThebes.cpp
@@ -5641,17 +5641,17 @@ nsTextFrame::PaintTextSelectionDecoratio
   nsTextRangeStyle selectedStyle;
   while (iterator.GetNextSegment(&xOffset, &offset, &length, &hyphenWidth,
                                  &type, &selectedStyle)) {
     gfxFloat advance = hyphenWidth +
       mTextRun->GetAdvanceWidth(offset, length, &aProvider);
     if (type == aSelectionType) {
       pt.x = (aFramePt.x + xOffset -
              (mTextRun->IsRightToLeft() ? advance : 0)) / app;
-      gfxFloat width = DeprecatedAbs(advance) / app;
+      gfxFloat width = Abs(advance) / app;
       gfxFloat xInFrame = pt.x - (aFramePt.x / app);
       DrawSelectionDecorations(aCtx, dirtyRect, aSelectionType, this,
                                aTextPaintStyle, selectedStyle, pt, xInFrame,
                                width, mAscent / app, decorationMetrics,
                                aCallbacks);
     }
     iterator.UpdateWithAdvance(advance);
   }
--- a/layout/style/nsStyleAnimation.cpp
+++ b/layout/style/nsStyleAnimation.cpp
@@ -405,23 +405,23 @@ nsStyleAnimation::ComputeDistance(nsCSSP
       int32_t startInt = aStartValue.GetIntValue();
       int32_t endInt = aEndValue.GetIntValue();
       aDistance = DeprecatedAbs(endInt - startInt);
       return true;
     }
     case eUnit_Coord: {
       nscoord startCoord = aStartValue.GetCoordValue();
       nscoord endCoord = aEndValue.GetCoordValue();
-      aDistance = DeprecatedAbs<double>(endCoord - startCoord);
+      aDistance = Abs(double(endCoord) - double(startCoord));
       return true;
     }
     case eUnit_Percent: {
       float startPct = aStartValue.GetPercentValue();
       float endPct = aEndValue.GetPercentValue();
-      aDistance = DeprecatedAbs<double>(endPct - startPct);
+      aDistance = Abs(double(endPct) - double(startPct));
       return true;
     }
     case eUnit_Float: {
 #ifdef MOZ_FLEXBOX
       // Special case for flex-grow and flex-shrink: animations are
       // disallowed between 0 and other values.
       if ((aProperty == eCSSProperty_flex_grow ||
            aProperty == eCSSProperty_flex_shrink) &&
@@ -429,17 +429,17 @@ nsStyleAnimation::ComputeDistance(nsCSSP
            aEndValue.GetFloatValue() == 0.0f) &&
           aStartValue.GetFloatValue() != aEndValue.GetFloatValue()) {
         return false;
       }
 #endif // MOZ_FLEXBOX
 
       float startFloat = aStartValue.GetFloatValue();
       float endFloat = aEndValue.GetFloatValue();
-      aDistance = DeprecatedAbs<double>(endFloat - startFloat);
+      aDistance = Abs(double(endFloat) - double(startFloat));
       return true;
     }
     case eUnit_Color: {
       // http://www.w3.org/TR/smil-animation/#animateColorElement says
       // that we should use Euclidean RGB cube distance.  However, we
       // have to extend that to RGBA.  For now, we'll just use the
       // Euclidean distance in the (part of the) 4-cube of premultiplied
       // colors.
@@ -1292,17 +1292,17 @@ Decompose2DMatrix(const gfxMatrix &aMatr
   D -= B * XYshear;
 
   float scaleY = sqrt(C * C + D * D);
   C /= scaleY;
   D /= scaleY;
   XYshear /= scaleY;
 
   // A*D - B*C should now be 1 or -1
-  NS_ASSERTION(0.99 < DeprecatedAbs(A*D - B*C) && DeprecatedAbs(A*D - B*C) < 1.01,
+  NS_ASSERTION(0.99 < Abs(A*D - B*C) && Abs(A*D - B*C) < 1.01,
                "determinant should now be 1 or -1");
   if (A * D < B * C) {
     A = -A;
     B = -B;
     C = -C;
     D = -D;
     XYshear = -XYshear;
     scaleX = -scaleX;
--- a/mfbt/MathAlgorithms.h
+++ b/mfbt/MathAlgorithms.h
@@ -61,19 +61,16 @@ template<typename T>
 struct AllowDeprecatedAbs : AllowDeprecatedAbsFixed<T> {};
 
 template<> struct AllowDeprecatedAbs<char> : IntegralConstant<bool, char(-1) < char(0)> {};
 template<> struct AllowDeprecatedAbs<signed char> : TrueType {};
 template<> struct AllowDeprecatedAbs<short> : TrueType {};
 template<> struct AllowDeprecatedAbs<int> : TrueType {};
 template<> struct AllowDeprecatedAbs<long> : TrueType {};
 template<> struct AllowDeprecatedAbs<long long> : TrueType {};
-template<> struct AllowDeprecatedAbs<float> : TrueType {};
-template<> struct AllowDeprecatedAbs<double> : TrueType {};
-template<> struct AllowDeprecatedAbs<long double> : TrueType {};
 
 } // namespace detail
 
 // DO NOT USE DeprecatedAbs.  It exists only until its callers can be converted
 // to Abs below, and it will be removed when all callers have been changed.
 template<typename T>
 inline typename mozilla::EnableIf<detail::AllowDeprecatedAbs<T>::value, T>::Type
 DeprecatedAbs(const T t)
@@ -88,37 +85,16 @@ DeprecatedAbs(const T t)
   // range [0, maxvalue]), doesn't produce maxvalue (because in twos-complement,
   // (minvalue + 1) == -maxvalue).
   MOZ_ASSERT(t >= 0 ||
              -(t + 1) != T((1ULL << (CHAR_BIT * sizeof(T) - 1)) - 1),
              "You can't negate the smallest possible negative integer!");
   return t >= 0 ? t : -t;
 }
 
-template<>
-inline float
-DeprecatedAbs<float>(const float f)
-{
-  return fabsf(f);
-}
-
-template<>
-inline double
-DeprecatedAbs<double>(const double d)
-{
-  return fabs(d);
-}
-
-template<>
-inline long double
-DeprecatedAbs<long double>(const long double d)
-{
-  return fabsl(d);
-}
-
 namespace detail {
 
 // For now mozilla::Abs only takes intN_T, the signed natural types, and
 // float/double/long double.  Feel free to add overloads for other standard,
 // signed types if you need them.
 
 template<typename T>
 struct AbsReturnTypeFixed;