Bug 1179315 - part 2 - make it more obvious that typeIDs of typed arrays are constants; r=lth
We need MOZ_CONSTEXPR on {Shared,}TypedArrayObject::ArrayTypeID for some
compilers to be able to constant-fold that function. But said compilers
didn't seem to understand MOZ_CONSTEXPR annotations on TypeIDOfType,
either on the template declaration or the individual specializations.
Instead, we convert TypeIDOfType into a traits template, so ArrayTypeID
can return a logical constant instead.
--- a/js/src/vm/SharedTypedArrayObject.cpp
+++ b/js/src/vm/SharedTypedArrayObject.cpp
@@ -93,17 +93,17 @@ class SharedTypedArrayObjectTemplate : p
// This is the max value of 'byteOffset': one below the length.
static const uint32_t MAX_BYTEOFFSET = MAX_LENGTH - 1;
public:
typedef NativeType ElementType;
typedef SharedTypedArrayObjectTemplate<NativeType> ThisTypedArrayObject;
typedef SharedArrayBufferObject BufferType;
- static Scalar::Type ArrayTypeID() { return TypeIDOfType<NativeType>(); }
+ static MOZ_CONSTEXPR Scalar::Type ArrayTypeID() { return TypeIDOfType<NativeType>::id; }
static bool ArrayTypeIsUnsigned() { return TypeIsUnsigned<NativeType>(); }
static bool ArrayTypeIsFloatingPoint() { return TypeIsFloatingPoint<NativeType>(); }
static const size_t BYTES_PER_ELEMENT = sizeof(ElementType);
static inline const Class* protoClass()
{
return &SharedTypedArrayObject::protoClasses[ArrayTypeID()];
--- a/js/src/vm/TypedArrayCommon.h
+++ b/js/src/vm/TypedArrayCommon.h
@@ -51,26 +51,26 @@ ValueIsLength(const Value& v, uint32_t*
*len = length;
return true;
}
return false;
}
-template<typename NativeType> static inline Scalar::Type TypeIDOfType();
-template<> inline Scalar::Type TypeIDOfType<int8_t>() { return Scalar::Int8; }
-template<> inline Scalar::Type TypeIDOfType<uint8_t>() { return Scalar::Uint8; }
-template<> inline Scalar::Type TypeIDOfType<int16_t>() { return Scalar::Int16; }
-template<> inline Scalar::Type TypeIDOfType<uint16_t>() { return Scalar::Uint16; }
-template<> inline Scalar::Type TypeIDOfType<int32_t>() { return Scalar::Int32; }
-template<> inline Scalar::Type TypeIDOfType<uint32_t>() { return Scalar::Uint32; }
-template<> inline Scalar::Type TypeIDOfType<float>() { return Scalar::Float32; }
-template<> inline Scalar::Type TypeIDOfType<double>() { return Scalar::Float64; }
-template<> inline Scalar::Type TypeIDOfType<uint8_clamped>() { return Scalar::Uint8Clamped; }
+template<typename NativeType> struct TypeIDOfType;
+template<> struct TypeIDOfType<int8_t> { static const Scalar::Type id = Scalar::Int8; };
+template<> struct TypeIDOfType<uint8_t> { static const Scalar::Type id = Scalar::Uint8; };
+template<> struct TypeIDOfType<int16_t> { static const Scalar::Type id = Scalar::Int16; };
+template<> struct TypeIDOfType<uint16_t> { static const Scalar::Type id = Scalar::Uint16; };
+template<> struct TypeIDOfType<int32_t> { static const Scalar::Type id = Scalar::Int32; };
+template<> struct TypeIDOfType<uint32_t> { static const Scalar::Type id = Scalar::Uint32; };
+template<> struct TypeIDOfType<float> { static const Scalar::Type id = Scalar::Float32; };
+template<> struct TypeIDOfType<double> { static const Scalar::Type id = Scalar::Float64; };
+template<> struct TypeIDOfType<uint8_clamped> { static const Scalar::Type id = Scalar::Uint8Clamped; };
inline bool
IsAnyTypedArray(JSObject* obj)
{
return obj->is<TypedArrayObject>() || obj->is<SharedTypedArrayObject>();
}
inline uint32_t
--- a/js/src/vm/TypedArrayObject.cpp
+++ b/js/src/vm/TypedArrayObject.cpp
@@ -192,17 +192,17 @@ namespace {
template<typename NativeType>
class TypedArrayObjectTemplate : public TypedArrayObject
{
friend class TypedArrayObject;
public:
typedef NativeType ElementType;
- static Scalar::Type ArrayTypeID() { return TypeIDOfType<NativeType>(); }
+ static MOZ_CONSTEXPR Scalar::Type ArrayTypeID() { return TypeIDOfType<NativeType>::id; }
static bool ArrayTypeIsUnsigned() { return TypeIsUnsigned<NativeType>(); }
static bool ArrayTypeIsFloatingPoint() { return TypeIsFloatingPoint<NativeType>(); }
static const size_t BYTES_PER_ELEMENT = sizeof(NativeType);
static JSObject*
createPrototype(JSContext* cx, JSProtoKey key)
{