Bug 1488191: Call into the VM only once to determine the TypedArray type for TypedArraySort. r=jandem

--HG--
extra : rebase_source : c3115f63798a62fc9fef89dd6f038884d96c3395
This commit is contained in:
André Bargull 2018-09-03 08:05:40 -07:00
Родитель eacdd2c298
Коммит 82fc23137b
3 изменённых файлов: 64 добавлений и 67 удалений

Просмотреть файл

@ -139,4 +139,14 @@
#define NOT_OBJECT_KIND_DESCRIPTOR 0
#define TYPEDARRAY_KIND_INT8 0
#define TYPEDARRAY_KIND_UINT8 1
#define TYPEDARRAY_KIND_INT16 2
#define TYPEDARRAY_KIND_UINT16 3
#define TYPEDARRAY_KIND_INT32 4
#define TYPEDARRAY_KIND_UINT32 5
#define TYPEDARRAY_KIND_FLOAT32 6
#define TYPEDARRAY_KIND_FLOAT64 7
#define TYPEDARRAY_KIND_UINT8CLAMPED 8
#endif

Просмотреть файл

@ -1191,22 +1191,40 @@ function TypedArraySort(comparefn) {
return obj;
if (comparefn === undefined) {
if (IsUint8TypedArray(obj)) {
var kind = GetTypedArrayKind(obj);
switch (kind) {
case TYPEDARRAY_KIND_UINT8:
case TYPEDARRAY_KIND_UINT8CLAMPED:
return CountingSort(obj, len, false /* signed */, TypedArrayCompareInt);
} else if (IsInt8TypedArray(obj)) {
case TYPEDARRAY_KIND_INT8:
return CountingSort(obj, len, true /* signed */, TypedArrayCompareInt);
} else if (IsUint16TypedArray(obj)) {
return RadixSort(obj, len, buffer, 2 /* nbytes */, false /* signed */, false /* floating */, TypedArrayCompareInt);
} else if (IsInt16TypedArray(obj)) {
return RadixSort(obj, len, buffer, 2 /* nbytes */, true /* signed */, false /* floating */, TypedArrayCompareInt);
} else if (IsUint32TypedArray(obj)) {
return RadixSort(obj, len, buffer, 4 /* nbytes */, false /* signed */, false /* floating */, TypedArrayCompareInt);
} else if (IsInt32TypedArray(obj)) {
return RadixSort(obj, len, buffer, 4 /* nbytes */, true /* signed */, false /* floating */, TypedArrayCompareInt);
} else if (IsFloat32TypedArray(obj)) {
return RadixSort(obj, len, buffer, 4 /* nbytes */, true /* signed */, true /* floating */, TypedArrayCompare);
case TYPEDARRAY_KIND_UINT16:
return RadixSort(obj, len, buffer,
2 /* nbytes */, false /* signed */, false /* floating */,
TypedArrayCompareInt);
case TYPEDARRAY_KIND_INT16:
return RadixSort(obj, len, buffer,
2 /* nbytes */, true /* signed */, false /* floating */,
TypedArrayCompareInt);
case TYPEDARRAY_KIND_UINT32:
return RadixSort(obj, len, buffer,
4 /* nbytes */, false /* signed */, false /* floating */,
TypedArrayCompareInt);
case TYPEDARRAY_KIND_INT32:
return RadixSort(obj, len, buffer,
4 /* nbytes */, true /* signed */, false /* floating */,
TypedArrayCompareInt);
case TYPEDARRAY_KIND_FLOAT32:
return RadixSort(obj, len, buffer,
4 /* nbytes */, true /* signed */, true /* floating */,
TypedArrayCompare);
case TYPEDARRAY_KIND_FLOAT64:
default:
// Include |default| to ensure Ion marks this call as the
// last instruction in the if-statement.
assert(kind === TYPEDARRAY_KIND_FLOAT64, "unexpected typed array kind");
return QuickSort(obj, len, TypedArrayCompare);
}
return QuickSort(obj, len, TypedArrayCompare);
}
// To satisfy step 2 from TypedArray SortCompare described in 22.2.3.26

Просмотреть файл

@ -1019,63 +1019,38 @@ intrinsic_SharedArrayBuffersMemorySame(JSContext* cx, unsigned argc, Value* vp)
}
static bool
intrinsic_IsSpecificTypedArray(JSContext* cx, unsigned argc, Value* vp, Scalar::Type type)
intrinsic_GetTypedArrayKind(JSContext* cx, unsigned argc, Value* vp)
{
CallArgs args = CallArgsFromVp(argc, vp);
MOZ_ASSERT(args.length() == 1);
MOZ_ASSERT(args[0].isObject());
static_assert(TYPEDARRAY_KIND_INT8 == Scalar::Type::Int8,
"TYPEDARRAY_KIND_INT8 doesn't match the scalar type");
static_assert(TYPEDARRAY_KIND_UINT8 == Scalar::Type::Uint8,
"TYPEDARRAY_KIND_UINT8 doesn't match the scalar type");
static_assert(TYPEDARRAY_KIND_INT16 == Scalar::Type::Int16,
"TYPEDARRAY_KIND_INT16 doesn't match the scalar type");
static_assert(TYPEDARRAY_KIND_UINT16 == Scalar::Type::Uint16,
"TYPEDARRAY_KIND_UINT16 doesn't match the scalar type");
static_assert(TYPEDARRAY_KIND_INT32 == Scalar::Type::Int32,
"TYPEDARRAY_KIND_INT32 doesn't match the scalar type");
static_assert(TYPEDARRAY_KIND_UINT32 == Scalar::Type::Uint32,
"TYPEDARRAY_KIND_UINT32 doesn't match the scalar type");
static_assert(TYPEDARRAY_KIND_FLOAT32 == Scalar::Type::Float32,
"TYPEDARRAY_KIND_FLOAT32 doesn't match the scalar type");
static_assert(TYPEDARRAY_KIND_FLOAT64 == Scalar::Type::Float64,
"TYPEDARRAY_KIND_FLOAT64 doesn't match the scalar type");
static_assert(TYPEDARRAY_KIND_UINT8CLAMPED == Scalar::Type::Uint8Clamped,
"TYPEDARRAY_KIND_UINT8CLAMPED doesn't match the scalar type");
JSObject* obj = &args[0].toObject();
Scalar::Type type = JS_GetArrayBufferViewType(obj);
bool isArray = JS_GetArrayBufferViewType(obj) == type;
args.rval().setBoolean(isArray);
args.rval().setInt32(static_cast<int32_t>(type));
return true;
}
static bool
intrinsic_IsUint8TypedArray(JSContext* cx, unsigned argc, Value* vp)
{
return intrinsic_IsSpecificTypedArray(cx, argc, vp, Scalar::Uint8) ||
intrinsic_IsSpecificTypedArray(cx, argc, vp, Scalar::Uint8Clamped);
}
static bool
intrinsic_IsInt8TypedArray(JSContext* cx, unsigned argc, Value* vp)
{
return intrinsic_IsSpecificTypedArray(cx, argc, vp, Scalar::Int8);
}
static bool
intrinsic_IsUint16TypedArray(JSContext* cx, unsigned argc, Value* vp)
{
return intrinsic_IsSpecificTypedArray(cx, argc, vp, Scalar::Uint16);
}
static bool
intrinsic_IsInt16TypedArray(JSContext* cx, unsigned argc, Value* vp)
{
return intrinsic_IsSpecificTypedArray(cx, argc, vp, Scalar::Int16);
}
static bool
intrinsic_IsUint32TypedArray(JSContext* cx, unsigned argc, Value* vp)
{
return intrinsic_IsSpecificTypedArray(cx, argc, vp, Scalar::Uint32);
}
static bool
intrinsic_IsInt32TypedArray(JSContext* cx, unsigned argc, Value* vp)
{
return intrinsic_IsSpecificTypedArray(cx, argc, vp, Scalar::Int32);
}
static bool
intrinsic_IsFloat32TypedArray(JSContext* cx, unsigned argc, Value* vp)
{
return intrinsic_IsSpecificTypedArray(cx, argc, vp, Scalar::Float32);
}
static bool
intrinsic_IsPossiblyWrappedTypedArray(JSContext* cx, unsigned argc, Value* vp)
{
@ -2545,13 +2520,7 @@ static const JSFunctionSpec intrinsic_functions[] = {
JS_FN("SharedArrayBuffersMemorySame",
intrinsic_SharedArrayBuffersMemorySame, 2,0),
JS_FN("IsUint8TypedArray", intrinsic_IsUint8TypedArray, 1,0),
JS_FN("IsInt8TypedArray", intrinsic_IsInt8TypedArray, 1,0),
JS_FN("IsUint16TypedArray", intrinsic_IsUint16TypedArray, 1,0),
JS_FN("IsInt16TypedArray", intrinsic_IsInt16TypedArray, 1,0),
JS_FN("IsUint32TypedArray", intrinsic_IsUint32TypedArray, 1,0),
JS_FN("IsInt32TypedArray", intrinsic_IsInt32TypedArray, 1,0),
JS_FN("IsFloat32TypedArray", intrinsic_IsFloat32TypedArray, 1,0),
JS_FN("GetTypedArrayKind", intrinsic_GetTypedArrayKind, 1,0),
JS_INLINABLE_FN("IsTypedArray",
intrinsic_IsInstanceOfBuiltin<TypedArrayObject>, 1,0,
IntrinsicIsTypedArray),