Bug 1225031 - Part 9: Inline methods from TypedArrayMethods and then remove TypedArrayMethods. r=lth
authorAndré Bargull <andre.bargull@gmail.com>
Fri, 27 Jan 2017 02:38:40 -0800
changeset 341163 75d9473b2744dce948c6277c13698cbf2146c1c6
parent 341162 2d1401b92435fcf678c36bbe59a1e3f431af24a7
child 341164 626ab78642929ec4c322ee45133ec2bbd93492bb
push id86642
push usercbook@mozilla.com
push dateTue, 07 Feb 2017 15:52:04 +0000
treeherdermozilla-inbound@75d9473b2744 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerslth
bugs1225031
milestone54.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 1225031 - Part 9: Inline methods from TypedArrayMethods and then remove TypedArrayMethods. r=lth
js/src/vm/TypedArrayObject-inl.h
js/src/vm/TypedArrayObject.cpp
--- a/js/src/vm/TypedArrayObject-inl.h
+++ b/js/src/vm/TypedArrayObject-inl.h
@@ -622,45 +622,11 @@ class ElementSpecific
         if (TypeIDOfType<T>::id == Scalar::Uint8Clamped)
             return T(d);
         if (TypeIsUnsigned<T>())
             return T(JS::ToUint32(d));
         return T(JS::ToInt32(d));
     }
 };
 
-template<typename T>
-class TypedArrayMethods
-{
-  public:
-    static bool
-    setFromTypedArray(JSContext* cx, Handle<TypedArrayObject*> target,
-                      Handle<TypedArrayObject*> source, uint32_t offset = 0)
-    {
-        if (target->isSharedMemory() || source->isSharedMemory())
-            return ElementSpecific<T, SharedOps>::setFromTypedArray(cx, target, source, offset);
-        return ElementSpecific<T, UnsharedOps>::setFromTypedArray(cx, target, source, offset);
-    }
-
-    static bool
-    setFromNonTypedArray(JSContext* cx, Handle<TypedArrayObject*> target, HandleObject source,
-                         uint32_t len, uint32_t offset = 0)
-    {
-        MOZ_ASSERT(!source->is<TypedArrayObject>(), "use setFromTypedArray");
-
-        if (target->isSharedMemory())
-            return ElementSpecific<T, SharedOps>::setFromNonTypedArray(cx, target, source, len, offset);
-        return ElementSpecific<T, UnsharedOps>::setFromNonTypedArray(cx, target, source, len, offset);
-    }
-
-    static bool
-    initFromIterablePackedArray(JSContext* cx, Handle<TypedArrayObject*> target,
-                                HandleArrayObject source)
-    {
-        if (target->isSharedMemory())
-            return ElementSpecific<T, SharedOps>::initFromIterablePackedArray(cx, target, source);
-        return ElementSpecific<T, UnsharedOps>::initFromIterablePackedArray(cx, target, source);
-    }
-};
-
 } // namespace js
 
 #endif // vm_TypedArrayObject_inl_h
--- a/js/src/vm/TypedArrayObject.cpp
+++ b/js/src/vm/TypedArrayObject.cpp
@@ -1267,18 +1267,24 @@ TypedArrayObjectTemplate<T>::fromTypedAr
     }
 
     // Steps 3, 4 (remaining part), 19-22.
     Rooted<TypedArrayObject*> obj(cx, makeInstance(cx, buffer, 0, elementLength, proto));
     if (!obj)
         return nullptr;
 
     // Step 18.d-g or 24.1.1.4 step 11.
-    if (!TypedArrayMethods<T>::setFromTypedArray(cx, obj, srcArray))
-        return nullptr;
+    MOZ_ASSERT(!obj->isSharedMemory());
+    if (isShared) {
+        if (!ElementSpecific<T, SharedOps>::setFromTypedArray(cx, obj, srcArray, 0))
+            return nullptr;
+    } else {
+        if (!ElementSpecific<T, UnsharedOps>::setFromTypedArray(cx, obj, srcArray, 0))
+            return nullptr;
+    }
 
     // Step 23.
     return obj;
 }
 
 static MOZ_ALWAYS_INLINE bool
 IsOptimizableInit(JSContext* cx, HandleObject iterable, bool* optimized)
 {
@@ -1324,17 +1330,18 @@ TypedArrayObjectTemplate<T>::fromObject(
         if (!maybeCreateArrayBuffer(cx, len, BYTES_PER_ELEMENT, nullptr, &buffer))
             return nullptr;
 
         Rooted<TypedArrayObject*> obj(cx, makeInstance(cx, buffer, 0, len, proto));
         if (!obj)
             return nullptr;
 
         // Steps 6.d-e.
-        if (!TypedArrayMethods<T>::initFromIterablePackedArray(cx, obj, array))
+        MOZ_ASSERT(!obj->isSharedMemory());
+        if (!ElementSpecific<T, UnsharedOps>::initFromIterablePackedArray(cx, obj, array))
             return nullptr;
 
         // Step 6.f (The assertion isn't applicable for the fast path).
 
         // Step 6.g.
         return obj;
     }
 
@@ -1390,17 +1397,18 @@ TypedArrayObjectTemplate<T>::fromObject(
     if (!maybeCreateArrayBuffer(cx, len, BYTES_PER_ELEMENT, nullptr, &buffer))
         return nullptr;
 
     Rooted<TypedArrayObject*> obj(cx, makeInstance(cx, buffer, 0, len, proto));
     if (!obj)
         return nullptr;
 
     // Steps 11-12.
-    if (!TypedArrayMethods<T>::setFromNonTypedArray(cx, obj, arrayLike, len))
+    MOZ_ASSERT(!obj->isSharedMemory());
+    if (!ElementSpecific<T, UnsharedOps>::setFromNonTypedArray(cx, obj, arrayLike, len))
         return nullptr;
 
     // Step 13.
     return obj;
 }
 
 bool
 TypedArrayConstructor(JSContext* cx, unsigned argc, Value* vp)
@@ -1485,16 +1493,38 @@ TypedArrayObject::protoAccessors[] = {
     JS_PSG("length", TypedArray_lengthGetter, 0),
     JS_PSG("buffer", TypedArray_bufferGetter, 0),
     JS_PSG("byteLength", TypedArray_byteLengthGetter, 0),
     JS_PSG("byteOffset", TypedArray_byteOffsetGetter, 0),
     JS_SELF_HOSTED_SYM_GET(toStringTag, "TypedArrayToStringTag", 0),
     JS_PS_END
 };
 
+template<typename T>
+static inline bool
+SetFromTypedArray(JSContext* cx, Handle<TypedArrayObject*> target,
+                  Handle<TypedArrayObject*> source, uint32_t offset)
+{
+    if (target->isSharedMemory() || source->isSharedMemory())
+        return ElementSpecific<T, SharedOps>::setFromTypedArray(cx, target, source, offset);
+    return ElementSpecific<T, UnsharedOps>::setFromTypedArray(cx, target, source, offset);
+}
+
+template<typename T>
+static inline bool
+SetFromNonTypedArray(JSContext* cx, Handle<TypedArrayObject*> target, HandleObject source,
+                     uint32_t len, uint32_t offset)
+{
+    MOZ_ASSERT(!source->is<TypedArrayObject>(), "use SetFromTypedArray");
+
+    if (target->isSharedMemory())
+        return ElementSpecific<T, SharedOps>::setFromNonTypedArray(cx, target, source, len, offset);
+    return ElementSpecific<T, UnsharedOps>::setFromNonTypedArray(cx, target, source, len, offset);
+}
+
 /* set(array[, offset]) */
 /* static */ bool
 TypedArrayObject::set_impl(JSContext* cx, const CallArgs& args)
 {
     MOZ_ASSERT(TypedArrayObject::is(args.thisv()));
 
     Rooted<TypedArrayObject*> target(cx, &args.thisv().toObject().as<TypedArrayObject>());
 
@@ -1522,17 +1552,17 @@ TypedArrayObject::set_impl(JSContext* cx
         if (source->length() > target->length() - offset) {
             JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, JSMSG_BAD_ARRAY_LENGTH);
             return false;
         }
 
         switch (target->type()) {
 #define SET_FROM_TYPED_ARRAY(T, N) \
           case Scalar::N: \
-            if (!TypedArrayMethods<T>::setFromTypedArray(cx, target, source, offset)) \
+            if (!SetFromTypedArray<T>(cx, target, source, offset)) \
                 return false; \
             break;
 JS_FOR_EACH_TYPED_ARRAY(SET_FROM_TYPED_ARRAY)
 #undef SET_FROM_TYPED_ARRAY
           default:
             MOZ_CRASH("Unsupported TypedArray type");
         }
     } else {
@@ -1543,17 +1573,17 @@ JS_FOR_EACH_TYPED_ARRAY(SET_FROM_TYPED_A
         if (uint32_t(offset) > target->length() || len > target->length() - offset) {
             JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, JSMSG_BAD_ARRAY_LENGTH);
             return false;
         }
 
         switch (target->type()) {
 #define SET_FROM_NON_TYPED_ARRAY(T, N) \
           case Scalar::N: \
-            if (!TypedArrayMethods<T>::setFromNonTypedArray(cx, target, arg0, len, offset)) \
+            if (!SetFromNonTypedArray<T>(cx, target, arg0, len, offset)) \
                 return false; \
             break;
 JS_FOR_EACH_TYPED_ARRAY(SET_FROM_NON_TYPED_ARRAY)
 #undef SET_FROM_NON_TYPED_ARRAY
           default:
             MOZ_CRASH("Unsupported TypedArray type");
         }
     }