mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-22 17:55:50 +00:00
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:
parent
f8f22a254c
commit
43d9783cff
@ -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);
|
||||
|
@ -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
|
||||
***/
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user