Bug 1398751 - Part 1: Add fast-path for typed arrays in js::GetElements to speed-up Function.apply with typed arrays. r=evilpie

This commit is contained in:
André Bargull 2017-09-11 22:06:39 +02:00
parent f8f22a254c
commit 43d9783cff
3 changed files with 33 additions and 0 deletions

View File

@ -455,6 +455,14 @@ js::GetElements(JSContext* cx, HandleObject aobj, uint32_t length, Value* vp)
}
}
if (aobj->is<TypedArrayObject>()) {
TypedArrayObject* typedArray = &aobj->as<TypedArrayObject>();
if (typedArray->length() == length) {
typedArray->getElements(vp);
return true;
}
}
if (js::GetElementsOp op = aobj->getOpsGetElements()) {
ElementAdder adder(cx, vp, length, ElementAdder::GetElement);
return op(cx, aobj, 0, length, &adder);

View File

@ -1887,6 +1887,25 @@ TypedArrayObject::setElement(TypedArrayObject& obj, uint32_t index, double d)
MOZ_CRASH("Unknown TypedArray type");
}
void
TypedArrayObject::getElements(Value* vp)
{
uint32_t length = this->length();
MOZ_ASSERT_IF(length > 0, !hasDetachedBuffer());
switch (type()) {
#define GET_ELEMENTS(T, N) \
case Scalar::N: \
for (uint32_t i = 0; i < length; ++i, ++vp) \
*vp = N##Array::getIndexValue(this, i); \
break;
JS_FOR_EACH_TYPED_ARRAY(GET_ELEMENTS)
#undef GET_ELEMENTS
default:
MOZ_CRASH("Unknown TypedArray type");
}
}
/***
*** JS impl
***/

View File

@ -183,6 +183,12 @@ class TypedArrayObject : public NativeObject
Value getElement(uint32_t index);
static void setElement(TypedArrayObject& obj, uint32_t index, double d);
/*
* Copy all elements from this typed array to vp. vp must point to rooted
* memory.
*/
void getElements(Value* vp);
void notifyBufferDetached(JSContext* cx, void* newData);
static bool