mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-08-22 04:13:06 +09:00
Optimize array length handling in ArraySetLength and array_unshift by caching property and argument counts
This commit is contained in:
parent
5a3a5606e2
commit
bd8939adb7
1 changed files with 10 additions and 8 deletions
|
|
@ -705,7 +705,8 @@ js::ArraySetLength(JSContext* cx, Handle<ArrayObject*> arr, HandleId id,
|
|||
if (!GetPropertyKeys(cx, arr, JSITER_OWNONLY | JSITER_HIDDEN, &props))
|
||||
return false;
|
||||
|
||||
for (size_t i = 0; i < props.length(); i++) {
|
||||
const size_t propCount = props.length();
|
||||
for (size_t i = 0; i < propCount; i++) {
|
||||
if (!CheckForInterrupt(cx))
|
||||
return false;
|
||||
|
||||
|
|
@ -2316,8 +2317,9 @@ js::array_unshift(JSContext* cx, unsigned argc, Value* vp)
|
|||
if (!GetLengthProperty(cx, obj, &length))
|
||||
return false;
|
||||
|
||||
const unsigned argCount = args.length();
|
||||
double newlen = length;
|
||||
if (args.length() > 0) {
|
||||
if (argCount > 0) {
|
||||
/* Slide up the array to make room for all args at the bottom. */
|
||||
if (length > 0) {
|
||||
// Only include a fast path for boxed arrays. Unboxed arrays can'nt
|
||||
|
|
@ -2332,22 +2334,22 @@ js::array_unshift(JSContext* cx, unsigned argc, Value* vp)
|
|||
ArrayObject* aobj = &obj->as<ArrayObject>();
|
||||
if (!aobj->lengthIsWritable())
|
||||
break;
|
||||
DenseElementResult result = aobj->ensureDenseElements(cx, length, args.length());
|
||||
DenseElementResult result = aobj->ensureDenseElements(cx, length, argCount);
|
||||
if (result != DenseElementResult::Success) {
|
||||
if (result == DenseElementResult::Failure)
|
||||
return false;
|
||||
MOZ_ASSERT(result == DenseElementResult::Incomplete);
|
||||
break;
|
||||
}
|
||||
aobj->moveDenseElements(args.length(), 0, length);
|
||||
for (uint32_t i = 0; i < args.length(); i++)
|
||||
aobj->moveDenseElements(argCount, 0, length);
|
||||
for (uint32_t i = 0; i < argCount; i++)
|
||||
aobj->setDenseElement(i, MagicValue(JS_ELEMENTS_HOLE));
|
||||
optimized = true;
|
||||
} while (false);
|
||||
|
||||
if (!optimized) {
|
||||
double last = length;
|
||||
double upperIndex = last + args.length();
|
||||
double upperIndex = last + argCount;
|
||||
RootedValue value(cx);
|
||||
do {
|
||||
--last, --upperIndex;
|
||||
|
|
@ -2368,10 +2370,10 @@ js::array_unshift(JSContext* cx, unsigned argc, Value* vp)
|
|||
}
|
||||
|
||||
/* Copy from args to the bottom of the array. */
|
||||
if (!InitArrayElements(cx, obj, 0, args.length(), args.array()))
|
||||
if (!InitArrayElements(cx, obj, 0, argCount, args.array()))
|
||||
return false;
|
||||
|
||||
newlen += args.length();
|
||||
newlen += argCount;
|
||||
}
|
||||
if (!SetLengthProperty(cx, obj, newlen))
|
||||
return false;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue