Bug 851769 part 1 - Handle arrays with length <= 1 more efficiently in Array.prototype.reverse. r=anba

--HG--
extra : rebase_source : fdf3bf32165011b3051bcd5ca1b6ad349ca7b8c1
This commit is contained in:
Jan de Mooij 2017-12-14 21:37:33 -06:00
Родитель 88be244907
Коммит d19ee0ef94
1 изменённых файлов: 10 добавлений и 2 удалений

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

@ -1525,8 +1525,10 @@ SetArrayElements(JSContext* cx, HandleObject obj, uint64_t start,
static DenseElementResult
ArrayReverseDenseKernel(JSContext* cx, HandleNativeObject obj, uint32_t length)
{
/* An empty array or an array with no elements is already reversed. */
if (length == 0 || obj->getDenseInitializedLength() == 0)
MOZ_ASSERT(length > 1);
// If there are no elements, we're done.
if (obj->getDenseInitializedLength() == 0)
return DenseElementResult::Success;
if (obj->denseElementsAreFrozen())
@ -1595,6 +1597,12 @@ js::array_reverse(JSContext* cx, unsigned argc, Value* vp)
if (!GetLengthProperty(cx, obj, &len))
return false;
// An empty array or an array with length 1 is already reversed.
if (len <= 1) {
args.rval().setObject(*obj);
return true;
}
if (IsPackedArrayOrNoExtraIndexedProperties(obj, len) && len <= UINT32_MAX) {
DenseElementResult result =
ArrayReverseDenseKernel(cx, obj.as<NativeObject>(), uint32_t(len));