mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 928917 - Use initDenseElements instead of NewDenseCopiedArray to speed up slice on arrays with holes. r=jandem
This commit is contained in:
parent
2994ac5b84
commit
dc2992372c
32
js/src/jit-test/tests/basic/array-slice.js
Normal file
32
js/src/jit-test/tests/basic/array-slice.js
Normal file
@ -0,0 +1,32 @@
|
||||
function check_specified_range_zero_base_slice() {
|
||||
var arr = new Array(32)
|
||||
arr[0]=0, arr[1]=1, arr[7]=7;
|
||||
var res = arr.slice(0,10);
|
||||
assertEq(arr[0],res[0]);
|
||||
assertEq(arr[1],res[1]);
|
||||
assertEq(arr[7],res[7]);
|
||||
assertEq(res.length,10);
|
||||
}
|
||||
|
||||
function check_specified_range_slice() {
|
||||
var arr = new Array(32)
|
||||
arr[0]=0, arr[6]=1, arr[8]=3;
|
||||
var res = arr.slice(5,9);
|
||||
assertEq(arr[6],res[1]);
|
||||
assertEq(arr[8],res[3]);
|
||||
assertEq(res.length,4);
|
||||
}
|
||||
|
||||
function check_all_range_slice() {
|
||||
var arr = new Array(32)
|
||||
arr[0]=0, arr[6]=1, arr[8]=3;
|
||||
var res = arr.slice();
|
||||
assertEq(arr[0],res[0]);
|
||||
assertEq(arr[6],res[6]);
|
||||
assertEq(arr[8],res[8]);
|
||||
assertEq(res.length,32);
|
||||
}
|
||||
|
||||
check_all_range_slice();
|
||||
check_specified_range_slice();
|
||||
check_specified_range_zero_base_slice();
|
@ -2725,23 +2725,22 @@ array_slice(JSContext *cx, unsigned argc, Value *vp)
|
||||
begin = end;
|
||||
|
||||
Rooted<ArrayObject*> narr(cx);
|
||||
|
||||
if (obj->is<ArrayObject>() && end <= obj->getDenseInitializedLength() &&
|
||||
!ObjectMayHaveExtraIndexedProperties(obj))
|
||||
{
|
||||
narr = NewDenseCopiedArray(cx, end - begin, obj, begin);
|
||||
if (!narr)
|
||||
return false;
|
||||
TryReuseArrayType(obj, narr);
|
||||
args.rval().setObject(*narr);
|
||||
return true;
|
||||
}
|
||||
|
||||
narr = NewDenseAllocatedArray(cx, end - begin);
|
||||
if (!narr)
|
||||
return false;
|
||||
TryReuseArrayType(obj, narr);
|
||||
|
||||
if (obj->is<ArrayObject>() && !ObjectMayHaveExtraIndexedProperties(obj)) {
|
||||
if (obj->getDenseInitializedLength() > begin) {
|
||||
uint32_t numSourceElements = obj->getDenseInitializedLength() - begin;
|
||||
uint32_t initLength = Min(numSourceElements, end - begin);
|
||||
narr->setDenseInitializedLength(initLength);
|
||||
narr->initDenseElements(0, &obj->getDenseElement(begin), initLength);
|
||||
}
|
||||
args.rval().setObject(*narr);
|
||||
return true;
|
||||
}
|
||||
|
||||
RootedValue value(cx);
|
||||
for (slot = begin; slot < end; slot++) {
|
||||
if (!JS_CHECK_OPERATION_LIMIT(cx) ||
|
||||
|
Loading…
Reference in New Issue
Block a user