Bug 1304638 - Return early from sorting if the array is single-element or empty. r?nbp
A single-element array is always sorted, by definition.
MozReview-Commit-ID: 9GXFGqomM9x
--- a/js/src/builtin/Array.js
+++ b/js/src/builtin/Array.js
@@ -198,16 +198,19 @@ function ArrayStaticSome(list, callbackf
/* ES6 draft 2016-1-15 22.1.3.25 Array.prototype.sort (comparefn) */
function ArraySort(comparefn) {
/* Step 1. */
var O = ToObject(this);
/* Step 2. */
var len = ToLength(O.length);
+ if (len <= 1)
+ return this;
+
/* 22.1.3.25.1 Runtime Semantics: SortCompare( x, y ) */
var wrappedCompareFn = comparefn;
comparefn = function(x, y) {
/* Steps 1-3. */
if (x === undefined) {
if (y === undefined)
return 0;
return 1;