From b0efbe0ef865090102fca888d96c325d89e90c29 Mon Sep 17 00:00:00 2001 From: Chris Peterson Date: Fri, 22 Jul 2016 22:05:45 -0700 Subject: [PATCH] Bug 1288603 - Remove NumericLimits.h because all platforms have numeric_limits. r=froydnj --- js/src/ctypes/CTypes.cpp | 51 ++++++++++++++++++------------------- mfbt/NumericLimits.h | 38 --------------------------- mfbt/Saturate.h | 11 ++++---- mfbt/moz.build | 1 - mfbt/tests/TestSaturate.cpp | 42 +++++++++++++++--------------- 5 files changed, 52 insertions(+), 91 deletions(-) delete mode 100644 mfbt/NumericLimits.h diff --git a/js/src/ctypes/CTypes.cpp b/js/src/ctypes/CTypes.cpp index bfa5b8f35e9d..4746c688dd04 100644 --- a/js/src/ctypes/CTypes.cpp +++ b/js/src/ctypes/CTypes.cpp @@ -8,9 +8,9 @@ #include "mozilla/FloatingPoint.h" #include "mozilla/MemoryReporting.h" -#include "mozilla/NumericLimits.h" #include "mozilla/Vector.h" +#include #include #include @@ -48,7 +48,6 @@ #include "jsobjinlines.h" using namespace std; -using mozilla::NumericLimits; using JS::AutoCheckCannotGC; @@ -2498,7 +2497,7 @@ JS_STATIC_ASSERT(sizeof(long long) == 8); JS_STATIC_ASSERT(sizeof(size_t) == sizeof(uintptr_t)); JS_STATIC_ASSERT(sizeof(float) == 4); JS_STATIC_ASSERT(sizeof(PRFuncPtr) == sizeof(void*)); -JS_STATIC_ASSERT(NumericLimits::is_signed); +JS_STATIC_ASSERT(numeric_limits::is_signed); // Templated helper to convert FromType to TargetType, for the default case // where the trivial POD constructor will do. @@ -2563,15 +2562,15 @@ static MOZ_ALWAYS_INLINE bool IsAlwaysExact() // 2) If FromType is signed, TargetType must also be signed. (Floating point // types are always signed.) // 3) If TargetType is an exact integral type, FromType must be also. - if (NumericLimits::digits < NumericLimits::digits) + if (numeric_limits::digits < numeric_limits::digits) return false; - if (NumericLimits::is_signed && - !NumericLimits::is_signed) + if (numeric_limits::is_signed && + !numeric_limits::is_signed) return false; - if (!NumericLimits::is_exact && - NumericLimits::is_exact) + if (!numeric_limits::is_exact && + numeric_limits::is_exact) return false; return true; @@ -2582,7 +2581,7 @@ static MOZ_ALWAYS_INLINE bool IsAlwaysExact() template struct IsExactImpl { static MOZ_ALWAYS_INLINE bool Test(FromType i, TargetType j) { - JS_STATIC_ASSERT(NumericLimits::is_exact); + JS_STATIC_ASSERT(numeric_limits::is_exact); return FromType(j) == i; } }; @@ -2591,7 +2590,7 @@ struct IsExactImpl { template struct IsExactImpl { static MOZ_ALWAYS_INLINE bool Test(FromType i, TargetType j) { - JS_STATIC_ASSERT(NumericLimits::is_exact); + JS_STATIC_ASSERT(numeric_limits::is_exact); return i >= 0 && FromType(j) == i; } }; @@ -2600,7 +2599,7 @@ struct IsExactImpl { template struct IsExactImpl { static MOZ_ALWAYS_INLINE bool Test(FromType i, TargetType j) { - JS_STATIC_ASSERT(NumericLimits::is_exact); + JS_STATIC_ASSERT(numeric_limits::is_exact); return TargetType(i) >= 0 && FromType(j) == i; } }; @@ -2611,7 +2610,7 @@ template static MOZ_ALWAYS_INLINE bool ConvertExact(FromType i, TargetType* result) { // Require that TargetType is integral, to simplify conversion. - JS_STATIC_ASSERT(NumericLimits::is_exact); + JS_STATIC_ASSERT(numeric_limits::is_exact); *result = Convert(i); @@ -2622,8 +2621,8 @@ static MOZ_ALWAYS_INLINE bool ConvertExact(FromType i, TargetType* result) // Return 'true' if 'i' is exactly representable in 'TargetType'. return IsExactImpl::is_signed, - NumericLimits::is_signed>::Test(i, *result); + numeric_limits::is_signed, + numeric_limits::is_signed>::Test(i, *result); } // Templated helper to determine if Type 'i' is negative. Default case @@ -2647,7 +2646,7 @@ struct IsNegativeImpl { template static MOZ_ALWAYS_INLINE bool IsNegative(Type i) { - return IsNegativeImpl::is_signed>::Test(i); + return IsNegativeImpl::is_signed>::Test(i); } // Implicitly convert val to bool, allowing bool, int, and double @@ -2681,7 +2680,7 @@ template static bool jsvalToInteger(JSContext* cx, Value val, IntegerType* result) { - JS_STATIC_ASSERT(NumericLimits::is_exact); + JS_STATIC_ASSERT(numeric_limits::is_exact); if (val.isInt32()) { // Make sure the integer fits in the alotted precision, and has the right @@ -2771,7 +2770,7 @@ template static bool jsvalToFloat(JSContext* cx, Value val, FloatType* result) { - JS_STATIC_ASSERT(!NumericLimits::is_exact); + JS_STATIC_ASSERT(!numeric_limits::is_exact); // The following casts may silently throw away some bits, but there's // no good way around it. Sternly requiring that the 64-bit double @@ -2829,7 +2828,7 @@ static bool StringToInteger(JSContext* cx, CharT* cp, size_t length, IntegerType* result, bool* overflow) { - JS_STATIC_ASSERT(NumericLimits::is_exact); + JS_STATIC_ASSERT(numeric_limits::is_exact); const CharT* end = cp + length; if (cp == end) @@ -2837,7 +2836,7 @@ StringToInteger(JSContext* cx, CharT* cp, size_t length, IntegerType* result, IntegerType sign = 1; if (cp[0] == '-') { - if (!NumericLimits::is_signed) + if (!numeric_limits::is_signed) return false; sign = -1; @@ -2906,7 +2905,7 @@ jsvalToBigInteger(JSContext* cx, IntegerType* result, bool* overflow) { - JS_STATIC_ASSERT(NumericLimits::is_exact); + JS_STATIC_ASSERT(numeric_limits::is_exact); if (val.isInt32()) { // Make sure the integer fits in the alotted precision, and has the right @@ -2978,7 +2977,7 @@ jsidToBigInteger(JSContext* cx, bool allowString, IntegerType* result) { - JS_STATIC_ASSERT(NumericLimits::is_exact); + JS_STATIC_ASSERT(numeric_limits::is_exact); if (JSID_IS_INT(val)) { // Make sure the integer fits in the alotted precision, and has the right @@ -3027,7 +3026,7 @@ template static bool jsvalToIntegerExplicit(Value val, IntegerType* result) { - JS_STATIC_ASSERT(NumericLimits::is_exact); + JS_STATIC_ASSERT(numeric_limits::is_exact); if (val.isDouble()) { // Convert -Inf, Inf, and NaN to 0; otherwise, convert by C-style cast. @@ -3108,7 +3107,7 @@ template void IntegerToString(IntegerType i, int radix, mozilla::Vector& result) { - JS_STATIC_ASSERT(NumericLimits::is_exact); + JS_STATIC_ASSERT(numeric_limits::is_exact); // The buffer must be big enough for all the bits of IntegerType to fit, // in base-2, including '-'. @@ -3195,7 +3194,7 @@ ConvertToJS(JSContext* cx, /* Return an Int64 or UInt64 object - do not convert to a JS number. */ \ uint64_t value; \ RootedObject proto(cx); \ - if (!NumericLimits::is_signed) { \ + if (!numeric_limits::is_signed) { \ value = *static_cast(data); \ /* Get ctypes.UInt64.prototype from ctypes.CType.prototype. */ \ proto = CType::GetProtoFromType(cx, typeObj, SLOT_UINT64PROTO); \ @@ -3210,7 +3209,7 @@ ConvertToJS(JSContext* cx, } \ \ JSObject* obj = Int64Base::Construct(cx, proto, value, \ - !NumericLimits::is_signed); \ + !numeric_limits::is_signed); \ if (!obj) \ return false; \ result.setObject(*obj); \ @@ -4172,7 +4171,7 @@ BuildDataSource(JSContext* cx, #define WRAPPED_INT_CASE(name, type, ffiType) \ case TYPE_##name: \ /* Serialize as a wrapped decimal integer. */ \ - if (!NumericLimits::is_signed) \ + if (!numeric_limits::is_signed) \ AppendString(result, "ctypes.UInt64(\""); \ else \ AppendString(result, "ctypes.Int64(\""); \ diff --git a/mfbt/NumericLimits.h b/mfbt/NumericLimits.h deleted file mode 100644 index 2ae8e7e51f6f..000000000000 --- a/mfbt/NumericLimits.h +++ /dev/null @@ -1,38 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * 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/. */ - -/* Compatibility with std::numeric_limits. */ - -#ifndef mozilla_NumericLimits_h -#define mozilla_NumericLimits_h - -#include "mozilla/Char16.h" - -#include -#include - -namespace mozilla { - -/** - * The NumericLimits class provides a compatibility layer with - * std::numeric_limits for char16_t, otherwise it is exactly the same as - * std::numeric_limits. Code which does not need std::numeric_limits - * should avoid using NumericLimits. - */ -template -class NumericLimits : public std::numeric_limits -{ -}; - -template<> -class NumericLimits : public std::numeric_limits -{ - // char16_t and uint16_t numeric limits should be exactly the same. -}; - -} // namespace mozilla - -#endif /* mozilla_NumericLimits_h */ diff --git a/mfbt/Saturate.h b/mfbt/Saturate.h index 5d3315e17be5..b79364d26809 100644 --- a/mfbt/Saturate.h +++ b/mfbt/Saturate.h @@ -11,9 +11,10 @@ #include "mozilla/Attributes.h" #include "mozilla/Move.h" -#include "mozilla/NumericLimits.h" #include "mozilla/TypeTraits.h" +#include + namespace mozilla { namespace detail { @@ -63,8 +64,8 @@ public: const T& operator+=(const T& aRhs) const { - const T min = NumericLimits::min(); - const T max = NumericLimits::max(); + const T min = std::numeric_limits::min(); + const T max = std::numeric_limits::max(); if (aRhs > static_cast(0)) { mValue = (max - aRhs) < mValue ? max : mValue + aRhs; @@ -76,8 +77,8 @@ public: const T& operator-=(const T& aRhs) const { - const T min = NumericLimits::min(); - const T max = NumericLimits::max(); + const T min = std::numeric_limits::min(); + const T max = std::numeric_limits::max(); if (aRhs > static_cast(0)) { mValue = (min + aRhs) > mValue ? min : mValue - aRhs; diff --git a/mfbt/moz.build b/mfbt/moz.build index e0f112a93cb1..fd752d53f3ea 100644 --- a/mfbt/moz.build +++ b/mfbt/moz.build @@ -62,7 +62,6 @@ EXPORTS.mozilla = [ 'Move.h', 'NotNull.h', 'NullPtr.h', - 'NumericLimits.h', 'Opaque.h', 'Pair.h', 'PodOperations.h', diff --git a/mfbt/tests/TestSaturate.cpp b/mfbt/tests/TestSaturate.cpp index cd1208ff8f31..06573ba4a2ed 100644 --- a/mfbt/tests/TestSaturate.cpp +++ b/mfbt/tests/TestSaturate.cpp @@ -7,10 +7,10 @@ #include #include -#include + +#include using mozilla::detail::Saturate; -using mozilla::NumericLimits; #define A(a) MOZ_RELEASE_ASSERT(a, "Test \'" #a "\' failed.") @@ -50,7 +50,7 @@ uint8_t StartValue() { // Picking a value near middle of uint8_t's range. - return static_cast(NumericLimits::max()); + return static_cast(std::numeric_limits::max()); } template<> @@ -58,7 +58,7 @@ uint16_t StartValue() { // Picking a value near middle of uint16_t's range. - return static_cast(NumericLimits::max()); + return static_cast(std::numeric_limits::max()); } template<> @@ -66,7 +66,7 @@ uint32_t StartValue() { // Picking a value near middle of uint32_t's range. - return static_cast(NumericLimits::max()); + return static_cast(std::numeric_limits::max()); } // Add @@ -154,28 +154,28 @@ template static void TestUpperBound() { - Saturate satValue(NumericLimits::max()); + Saturate satValue(std::numeric_limits::max()); - A(--satValue == (NumericLimits::max() - 1)); - A(++satValue == (NumericLimits::max())); - A(++satValue == (NumericLimits::max())); // don't overflow here - A(++satValue == (NumericLimits::max())); // don't overflow here - A(--satValue == (NumericLimits::max() - 1)); // back at (max - 1) - A(--satValue == (NumericLimits::max() - 2)); + A(--satValue == (std::numeric_limits::max() - 1)); + A(++satValue == (std::numeric_limits::max())); + A(++satValue == (std::numeric_limits::max())); // don't overflow here + A(++satValue == (std::numeric_limits::max())); // don't overflow here + A(--satValue == (std::numeric_limits::max() - 1)); // back at (max - 1) + A(--satValue == (std::numeric_limits::max() - 2)); } template static void TestLowerBound() { - Saturate satValue(NumericLimits::min()); + Saturate satValue(std::numeric_limits::min()); - A(++satValue == (NumericLimits::min() + 1)); - A(--satValue == (NumericLimits::min())); - A(--satValue == (NumericLimits::min())); // don't overflow here - A(--satValue == (NumericLimits::min())); // don't overflow here - A(++satValue == (NumericLimits::min() + 1)); // back at (max + 1) - A(++satValue == (NumericLimits::min() + 2)); + A(++satValue == (std::numeric_limits::min() + 1)); + A(--satValue == (std::numeric_limits::min())); + A(--satValue == (std::numeric_limits::min())); // don't overflow here + A(--satValue == (std::numeric_limits::min())); // don't overflow here + A(++satValue == (std::numeric_limits::min() + 1)); // back at (max + 1) + A(++satValue == (std::numeric_limits::min() + 2)); } // Framework @@ -187,8 +187,8 @@ TestAll() { // Assert that we don't accidently hit type's range limits in tests. const T value = StartValue(); - A(NumericLimits::min() + static_cast(sNumOps) <= value); - A(NumericLimits::max() - static_cast(sNumOps) >= value); + A(std::numeric_limits::min() + static_cast(sNumOps) <= value); + A(std::numeric_limits::max() - static_cast(sNumOps) >= value); TestPrefixIncr(); TestPostfixIncr();