Bug 799122 - Eagerly allocate dense elements for small arrays. r=luke

This commit is contained in:
Jan de Mooij 2013-07-03 13:17:29 +02:00
parent ef60a1c7b9
commit b1e1601055

View File

@ -2788,7 +2788,16 @@ js_Array(JSContext *cx, unsigned argc, Value *vp)
}
}
RootedObject obj(cx, NewDenseUnallocatedArray(cx, length));
/*
* Allocate dense elements eagerly for small arrays, to avoid reallocating
* elements when filling the array.
*/
static const uint32_t ArrayEagerAllocationMaxLength = 2048;
RootedObject obj(cx);
obj = (length <= ArrayEagerAllocationMaxLength)
? NewDenseAllocatedArray(cx, length)
: NewDenseUnallocatedArray(cx, length);
if (!obj)
return false;
Rooted<ArrayObject*> arr(cx, &obj->as<ArrayObject>());