Bug 913603 - Re-inline SaturatingUnionEdges and remove the unused SaturatingInflate - r=mats, a=lsblakk
authorBenoit Jacob <bjacob@mozilla.com>
Tue, 17 Sep 2013 17:53:37 -0400
changeset 160607 9b349fca4874945f44910fbb75715fa77504e947
parent 160606 472e707d5b726f0fbc25cdae258aa8d3b1fd9f3b
child 160608 53cb95cfe6dccea99f142771afaf81ed920f910a
push id2961
push userlsblakk@mozilla.com
push dateMon, 28 Oct 2013 21:59:28 +0000
treeherdermozilla-beta@73ef4f13486f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmats, lsblakk
bugs913603
milestone26.0a2
Bug 913603 - Re-inline SaturatingUnionEdges and remove the unused SaturatingInflate - r=mats, a=lsblakk
gfx/src/nsRect.cpp
gfx/src/nsRect.h
--- a/gfx/src/nsRect.cpp
+++ b/gfx/src/nsRect.cpp
@@ -3,19 +3,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsRect.h"
 #include "mozilla/gfx/Types.h"          // for NS_SIDE_BOTTOM, etc
 #include "nsDeviceContext.h"            // for nsDeviceContext
 #include "nsStringGlue.h"               // for nsAutoString, etc
 #include "prtypes.h"                    // for PR_STATIC_ASSERT
-#include "nsDebug.h"                    // for NS_WARNING
 #include "nsMargin.h"                   // for nsMargin
-#include <algorithm>                    // for min, max
 
 // the mozilla::css::Side sequence must match the nsMargin nscoord sequence
 PR_STATIC_ASSERT((NS_SIDE_TOP == 0) && (NS_SIDE_RIGHT == 1) && (NS_SIDE_BOTTOM == 2) && (NS_SIDE_LEFT == 3));
 
 #ifdef DEBUG
 // Diagnostics
 
 FILE* operator<<(FILE* out, const nsRect& rect)
@@ -36,94 +34,8 @@ FILE* operator<<(FILE* out, const nsRect
   tmp.AppendFloat(NSAppUnitsToFloatPixels(rect.height,
                        nsDeviceContext::AppUnitsPerCSSPixel()));
   tmp.AppendLiteral("}");
   fputs(NS_LossyConvertUTF16toASCII(tmp).get(), out);
   return out;
 }
 
 #endif // DEBUG
-
-nsRect
-nsRect::SaturatingUnionEdges(const nsRect& aRect) const
-{
-#ifdef NS_COORD_IS_FLOAT
-  return UnionEdges(aRect);
-#else
-  nsRect result;
-  result.x = std::min(aRect.x, x);
-  int64_t w = std::max(int64_t(aRect.x) + aRect.width, int64_t(x) + width) - result.x;
-  if (MOZ_UNLIKELY(w > nscoord_MAX)) {
-    NS_WARNING("Overflowed nscoord_MAX in conversion to nscoord width");
-    // Clamp huge negative x to nscoord_MIN / 2 and try again.
-    result.x = std::max(result.x, nscoord_MIN / 2);
-    w = std::max(int64_t(aRect.x) + aRect.width, int64_t(x) + width) - result.x;
-    if (MOZ_UNLIKELY(w > nscoord_MAX)) {
-      w = nscoord_MAX;
-    }
-  }
-  result.width = nscoord(w);
-
-  result.y = std::min(aRect.y, y);
-  int64_t h = std::max(int64_t(aRect.y) + aRect.height, int64_t(y) + height) - result.y;
-  if (MOZ_UNLIKELY(h > nscoord_MAX)) {
-    NS_WARNING("Overflowed nscoord_MAX in conversion to nscoord height");
-    // Clamp huge negative y to nscoord_MIN / 2 and try again.
-    result.y = std::max(result.y, nscoord_MIN / 2);
-    h = std::max(int64_t(aRect.y) + aRect.height, int64_t(y) + height) - result.y;
-    if (MOZ_UNLIKELY(h > nscoord_MAX)) {
-      h = nscoord_MAX;
-    }
-  }
-  result.height = nscoord(h);
-  return result;
-#endif
-}
-
-void
-nsRect::SaturatingInflate(const nsMargin& aMargin)
-{
-#ifdef NS_COORD_IS_FLOAT
-  Inflate(aMargin);
-#else
-  int64_t nx = int64_t(x) - aMargin.left;
-  int64_t w = int64_t(width) + int64_t(aMargin.left) + aMargin.right;
-  if (MOZ_UNLIKELY(w > nscoord_MAX)) {
-    NS_WARNING("Overflowed nscoord_MAX in conversion to nscoord width");
-    int64_t xdiff = nx - nscoord_MIN / 2;
-    if (xdiff < 0) {
-      // Clamp huge negative x to nscoord_MIN / 2 and try again.
-      nx = nscoord_MIN / 2;
-      w += xdiff;
-    }
-    if (MOZ_UNLIKELY(w > nscoord_MAX)) {
-      w = nscoord_MAX;
-    }
-  }
-  width = nscoord(w);
-  if (MOZ_UNLIKELY(nx < nscoord_MIN)) {
-    NS_WARNING("Underflowed nscoord_MIN in conversion to nscoord x");
-    nx = nscoord_MIN;
-  }
-  x = nscoord(nx);
-
-  int64_t ny = int64_t(y) - aMargin.top;
-  int64_t h = int64_t(height) + int64_t(aMargin.top) + aMargin.bottom;
-  if (MOZ_UNLIKELY(h > nscoord_MAX)) {
-    NS_WARNING("Overflowed nscoord_MAX in conversion to nscoord height");
-    int64_t ydiff = ny - nscoord_MIN / 2;
-    if (ydiff < 0) {
-      // Clamp huge negative y to nscoord_MIN / 2 and try again.
-      ny = nscoord_MIN / 2;
-      h += ydiff;
-    }
-    if (MOZ_UNLIKELY(h > nscoord_MAX)) {
-      h = nscoord_MAX;
-    }
-  }
-  height = nscoord(h);
-  if (MOZ_UNLIKELY(ny < nscoord_MIN)) {
-    NS_WARNING("Underflowed nscoord_MIN in conversion to nscoord y");
-    ny = nscoord_MIN;
-  }
-  y = nscoord(ny);
-#endif
-}
--- a/gfx/src/nsRect.h
+++ b/gfx/src/nsRect.h
@@ -4,16 +4,18 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 
 #ifndef NSRECT_H
 #define NSRECT_H
 
 #include <stdio.h>                      // for FILE
 #include <stdint.h>                     // for int32_t, int64_t
+#include <algorithm>                    // for min/max
+#include "nsDebug.h"                    // for NS_WARNING
 #include "gfxCore.h"                    // for NS_GFX
 #include "mozilla/Likely.h"             // for MOZ_UNLIKELY
 #include "mozilla/gfx/BaseRect.h"       // for BaseRect
 #include "nsCoord.h"                    // for nscoord, etc
 #include "nsPoint.h"                    // for nsIntPoint, nsPoint
 #include "nsSize.h"                     // for nsIntSize, nsSize
 #include "nsTraceRefcnt.h"              // for MOZ_COUNT_CTOR, etc
 #include "nscore.h"                     // for NS_BUILD_REFCNT_LOGGING
@@ -48,37 +50,65 @@ struct NS_GFX nsRect :
   }
 
 #ifdef NS_BUILD_REFCNT_LOGGING
   ~nsRect() {
     MOZ_COUNT_DTOR(nsRect);
   }
 #endif
 
-  // A version of Inflate that caps the values to the nscoord range.
-  // x & y is capped at the minimum value nscoord_MIN and
-  // width & height is capped at the maximum value nscoord_MAX.
-  void SaturatingInflate(const nsMargin& aMargin);
-
   // We have saturating versions of all the Union methods. These avoid
   // overflowing nscoord values in the 'width' and 'height' fields by
   // clamping the width and height values to nscoord_MAX if necessary.
 
   nsRect SaturatingUnion(const nsRect& aRect) const
   {
     if (IsEmpty()) {
       return aRect;
     } else if (aRect.IsEmpty()) {
       return *static_cast<const nsRect*>(this);
     } else {
       return SaturatingUnionEdges(aRect);
     }
   }
 
-  nsRect SaturatingUnionEdges(const nsRect& aRect) const;
+  nsRect SaturatingUnionEdges(const nsRect& aRect) const
+  {
+#ifdef NS_COORD_IS_FLOAT
+    return UnionEdges(aRect);
+#else
+    nsRect result;
+    result.x = std::min(aRect.x, x);
+    int64_t w = std::max(int64_t(aRect.x) + aRect.width, int64_t(x) + width) - result.x;
+    if (MOZ_UNLIKELY(w > nscoord_MAX)) {
+      NS_WARNING("Overflowed nscoord_MAX in conversion to nscoord width");
+      // Clamp huge negative x to nscoord_MIN / 2 and try again.
+      result.x = std::max(result.x, nscoord_MIN / 2);
+      w = std::max(int64_t(aRect.x) + aRect.width, int64_t(x) + width) - result.x;
+      if (MOZ_UNLIKELY(w > nscoord_MAX)) {
+        w = nscoord_MAX;
+      }
+    }
+    result.width = nscoord(w);
+
+    result.y = std::min(aRect.y, y);
+    int64_t h = std::max(int64_t(aRect.y) + aRect.height, int64_t(y) + height) - result.y;
+    if (MOZ_UNLIKELY(h > nscoord_MAX)) {
+      NS_WARNING("Overflowed nscoord_MAX in conversion to nscoord height");
+      // Clamp huge negative y to nscoord_MIN / 2 and try again.
+      result.y = std::max(result.y, nscoord_MIN / 2);
+      h = std::max(int64_t(aRect.y) + aRect.height, int64_t(y) + height) - result.y;
+      if (MOZ_UNLIKELY(h > nscoord_MAX)) {
+        h = nscoord_MAX;
+      }
+    }
+    result.height = nscoord(h);
+    return result;
+#endif
+  }
 
 #ifndef NS_COORD_IS_FLOAT
   // Make all nsRect Union methods be saturating.
   nsRect UnionEdges(const nsRect& aRect) const
   {
     return SaturatingUnionEdges(aRect);
   }
   void UnionRectEdges(const nsRect& aRect1, const nsRect& aRect2)