Bug 1517259 - Part 6: Replace CalculateAllocSize with simple multiplication. r=tcampbell
authorAndré Bargull <andre.bargull@gmail.com>
Thu, 03 Jan 2019 02:50:40 -0800
changeset 509947 26f01305411cec2aa1a186f14de45b4822d65345
parent 509946 fbe6986e02b55160283bcdc0ced30bb47122798f
child 509948 f428c73aa133a363c4fb971112d1718575d4523e
push id10547
push userffxbld-merge
push dateMon, 21 Jan 2019 13:03:58 +0000
treeherdermozilla-beta@24ec1916bffe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstcampbell
bugs1517259
milestone66.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 1517259 - Part 6: Replace CalculateAllocSize with simple multiplication. r=tcampbell
js/src/jit/MacroAssembler.cpp
js/src/vm/TypedArrayObject.cpp
--- a/js/src/jit/MacroAssembler.cpp
+++ b/js/src/jit/MacroAssembler.cpp
@@ -1170,29 +1170,18 @@ static void AllocateObjectBufferWithInit
   // raise an invalid argument exception or create a correct object with zero
   // elements.
   if (count <= 0 || uint32_t(count) >= INT32_MAX / obj->bytesPerElement()) {
     obj->setFixedSlot(TypedArrayObject::LENGTH_SLOT, Int32Value(0));
     return;
   }
 
   obj->setFixedSlot(TypedArrayObject::LENGTH_SLOT, Int32Value(count));
-  size_t nbytes;
-
-  switch (obj->type()) {
-#define CREATE_TYPED_ARRAY(T, N)                                \
-  case Scalar::N:                                               \
-    MOZ_ALWAYS_TRUE(js::CalculateAllocSize<T>(count, &nbytes)); \
-    break;
-    JS_FOR_EACH_TYPED_ARRAY(CREATE_TYPED_ARRAY)
-#undef CREATE_TYPED_ARRAY
-    default:
-      MOZ_CRASH("Unsupported TypedArray type");
-  }
-
+
+  size_t nbytes = count * obj->bytesPerElement();
   MOZ_ASSERT((CheckedUint32(nbytes) + sizeof(Value)).isValid());
 
   nbytes = JS_ROUNDUP(nbytes, sizeof(Value));
   void* buf = cx->nursery().allocateBuffer(obj, nbytes);
   if (buf) {
     obj->initPrivate(buf);
     memset(buf, 0, nbytes);
   }
--- a/js/src/vm/TypedArrayObject.cpp
+++ b/js/src/vm/TypedArrayObject.cpp
@@ -521,19 +521,17 @@ class TypedArrayObjectTemplate : public 
   static TypedArrayObject* makeTypedArrayWithTemplate(
       JSContext* cx, TypedArrayObject* templateObj, int32_t len) {
     if (len < 0 || uint32_t(len) >= INT32_MAX / BYTES_PER_ELEMENT) {
       JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr,
                                 JSMSG_BAD_ARRAY_LENGTH);
       return nullptr;
     }
 
-    size_t nbytes;
-    MOZ_ALWAYS_TRUE(js::CalculateAllocSize<NativeType>(len, &nbytes));
-
+    size_t nbytes = len * BYTES_PER_ELEMENT;
     bool fitsInline = nbytes <= INLINE_BUFFER_LIMIT;
 
     AutoSetNewObjectMetadata metadata(cx);
 
     const Class* clasp = templateObj->group()->clasp();
     gc::AllocKind allocKind = !fitsInline ? gc::GetGCObjectKind(clasp)
                                           : AllocKindForLazyBuffer(nbytes);
     MOZ_ASSERT(CanBeFinalizedInBackground(allocKind, clasp));