Skip to content

Commit

Permalink
Bug 1331475 - Don't atomize "ArraySort" for every call to the self-ho…
Browse files Browse the repository at this point in the history
…sted ArraySort function. r=till

--HG--
extra : rebase_source : 6fedc7009113acc44bda7893aeee7dac04e4a31e
  • Loading branch information
anba committed Jan 17, 2017
1 parent 90ef21d commit 4c88a6f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 23 deletions.
27 changes: 4 additions & 23 deletions js/src/jsarray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1895,19 +1895,11 @@ js::array_sort(JSContext* cx, unsigned argc, Value* vp)
* Non-optimized user supplied comparators perform much better when
* called from within a self-hosted sorting function.
*/
RootedAtom selfHostedSortAtom(cx, Atomize(cx, "ArraySort", 9));
RootedPropertyName selfHostedSortName(cx, selfHostedSortAtom->asPropertyName());
RootedValue selfHostedSortValue(cx);
FixedInvokeArgs<1> args2(cx);
args2[0].set(fval);

if (!GlobalObject::getIntrinsicValue(cx, cx->global(), selfHostedSortName,
&selfHostedSortValue)) {
return false;
}

MOZ_ASSERT(selfHostedSortValue.isObject());
MOZ_ASSERT(selfHostedSortValue.toObject().is<JSFunction>());

return Call(cx, selfHostedSortValue, args.thisv(), fval, args.rval());
RootedValue thisv(cx, ObjectValue(*obj));
return CallSelfHostedFunction(cx, cx->names().ArraySort, thisv, args2, args.rval());
}

uint32_t len;
Expand All @@ -1932,15 +1924,6 @@ js::array_sort(JSContext* cx, unsigned argc, Value* vp)
}
#endif

/*
* Initialize vec as a root. We will clear elements of vec one by
* one while increasing the rooted amount of vec when we know that the
* property at the corresponding index exists and its value must be rooted.
*
* In this way when sorting a huge mostly sparse array we will not
* access the tail of vec corresponding to properties that do not
* exist, allowing OS to avoiding committing RAM. See bug 330812.
*/
size_t n, undefs;
{
Rooted<GCVector<Value>> vec(cx, GCVector<Value>(cx));
Expand All @@ -1963,7 +1946,6 @@ js::array_sort(JSContext* cx, unsigned argc, Value* vp)
if (!CheckForInterrupt(cx))
return false;

/* Clear vec[newlen] before including it in the rooted set. */
bool hole;
if (!GetElement(cx, obj, i, &hole, &v))
return false;
Expand All @@ -1978,7 +1960,6 @@ js::array_sort(JSContext* cx, unsigned argc, Value* vp)
allInts = allInts && v.isInt32();
}


/*
* If the array only contains holes, we're done. But if it contains
* undefs, those must be sorted to the front of the array.
Expand Down
1 change: 1 addition & 0 deletions js/src/vm/CommonPropertyNames.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
macro(ArrayBufferSpecies, ArrayBufferSpecies, "ArrayBufferSpecies") \
macro(ArrayIterator, ArrayIterator, "Array Iterator") \
macro(ArrayIteratorNext, ArrayIteratorNext, "ArrayIteratorNext") \
macro(ArraySort, ArraySort, "ArraySort") \
macro(ArraySpecies, ArraySpecies, "ArraySpecies") \
macro(ArraySpeciesCreate, ArraySpeciesCreate, "ArraySpeciesCreate") \
macro(ArrayToLocaleString, ArrayToLocaleString, "ArrayToLocaleString") \
Expand Down

0 comments on commit 4c88a6f

Please sign in to comment.