Back out cff7378485bc (bug 869238), Windows bustage (at least). r=redness
authorJeff Walden <jwalden@mit.edu>
Tue, 07 May 2013 13:45:43 -0700
changeset 131145 3baae116d26fd9735c53cbe1e8d86f9249a283b6
parent 131144 11a3ee38afff9c5108e053ec4e9a5db730f3fd20
child 131146 da02b1166a5c30ffc54bc018486de8d8ab782257
push id27714
push userjwalden@mit.edu
push dateTue, 07 May 2013 20:46:02 +0000
treeherdermozilla-inbound@3baae116d26f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersredness
bugs869238
milestone23.0a1
backs outcff7378485bcfc4693ee192c71d16fece9101e92
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
Back out cff7378485bc (bug 869238), Windows bustage (at least). r=redness
mfbt/Casting.h
--- a/mfbt/Casting.h
+++ b/mfbt/Casting.h
@@ -26,115 +26,63 @@ template<typename From,
          ToSignedness = IsSigned<To>::value ? ToIsSigned : ToIsUnsigned>
 struct BoundsCheckImpl;
 
 // Implicit conversions on operands to binary operations make this all a bit
 // hard to verify.  Attempt to ease the pain below by *only* comparing values
 // that are obviously the same type (and will undergo no further conversions),
 // even when it's not strictly necessary, for explicitness.
 
-enum UUComparison { FromIsBigger, FromIsNotBigger };
-
-// Unsigned-to-unsigned range check
-
-template<typename From, typename To,
-         UUComparison = (sizeof(From) > sizeof(To)) ? FromIsBigger : FromIsNotBigger>
-struct UnsignedUnsignedCheck;
-
-template<typename From, typename To>
-struct UnsignedUnsignedCheck<From, To, FromIsBigger>
-{
-  public:
-    static bool check(const From from) {
-      return from <= From(To(-1));
-    }
-};
-
-template<typename From, typename To>
-struct UnsignedUnsignedCheck<From, To, FromIsNotBigger>
-{
-  public:
-    static bool check(const From from) {
-      return true;
-    }
-};
-
 template<typename From, typename To>
 struct BoundsCheckImpl<From, To, FromIsUnsigned, ToIsUnsigned>
 {
   public:
     static bool check(const From from) {
-      return UnsignedUnsignedCheck<From, To>::check(from);
+      typedef typename Conditional<sizeof(From) >= sizeof(To), From, To>::Type
+              LargerType;
+      return LargerType(from) <= LargerType(To(-1));
     }
 };
 
-// Signed-to-unsigned range check
-
 template<typename From, typename To>
 struct BoundsCheckImpl<From, To, FromIsSigned, ToIsUnsigned>
 {
   public:
     static bool check(const From from) {
       if (from < 0)
         return false;
       if (sizeof(To) >= sizeof(From))
-        return true;
+        return To(from) <= To(-1);
       return from <= From(To(-1));
     }
 };
 
-// Unsigned-to-signed range check
-
-enum USComparison { FromIsSmaller, FromIsNotSmaller };
-
-template<typename From, typename To,
-         USComparison = sizeof(From) < sizeof(To) ? FromIsSmaller : FromIsNotSmaller>
-struct UnsignedSignedCheck;
-
-template<typename From, typename To>
-struct UnsignedSignedCheck<From, To, FromIsSmaller>
-{
-  public:
-    static bool check(const From from) {
-      return true;
-    }
-};
-
-template<typename From, typename To>
-struct UnsignedSignedCheck<From, To, FromIsNotSmaller>
-{
-  public:
-    static bool check(const From from) {
-      const To MaxValue = To((1ULL << (CHAR_BIT * sizeof(To) - 1)) - 1);
-      return from <= From(MaxValue);
-    }
-};
-
 template<typename From, typename To>
 struct BoundsCheckImpl<From, To, FromIsUnsigned, ToIsSigned>
 {
   public:
     static bool check(const From from) {
-      return UnsignedSignedCheck<From, To>::check(from);
+      if (sizeof(From) < sizeof(To))
+        return true;
+      const To MaxValue = To((1ULL << (CHAR_BIT * sizeof(To) - 1)) - 1);
+      return from <= From(MaxValue);
     }
 };
 
-// Signed-to-signed range check
-
 template<typename From, typename To>
 struct BoundsCheckImpl<From, To, FromIsSigned, ToIsSigned>
 {
   public:
     static bool check(const From from) {
-      if (sizeof(From) <= sizeof(To))
-        return true;
+      typedef typename Conditional<sizeof(To) >= sizeof(From), To, From>::Type
+              LargerType;
       const To MaxValue = To((1ULL << (CHAR_BIT * sizeof(To) - 1)) - 1);
       const To MinValue = -MaxValue - To(1);
-      return From(MinValue) <= from &&
-             From(from) <= From(MaxValue);
+      return LargerType(MinValue) <= LargerType(from) &&
+             LargerType(from) <= LargerType(MaxValue);
     }
 };
 
 template<typename From, typename To,
          bool TypesAreIntegral = IsIntegral<From>::value && IsIntegral<To>::value>
 class BoundsChecker;
 
 template<typename From>