Bug 1290676 - Call InsertionSort when |denseLen < 24| in MergeSort. r=mrrrgn

--HG--
extra : rebase_source : fb647e2f9d660c5070f265c18fb194a40d7cb843
This commit is contained in:
Jinank Jain 2016-08-08 11:38:47 -04:00
Родитель b2d36aaaeb
Коммит eb044fd113
1 изменённых файлов: 6 добавлений и 6 удалений

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

@ -230,11 +230,6 @@ function MoveHoles(sparse, sparseLen, dense, denseLen) {
// Iterative, bottom up, mergesort.
function MergeSort(array, len, comparefn) {
// To save effort we will do all of our work on a dense list,
// then create holes at the end.
var denseList = new List();
var denseLen = 0;
// Until recently typed arrays had no sort method. To work around that
// many users passed them to Array.prototype.sort. Now that we have a
// typed array specific sorting method it makes sense to divert to it
@ -243,6 +238,11 @@ function MergeSort(array, len, comparefn) {
return callFunction(TypedArraySort, array, comparefn);
}
// To save effort we will do all of our work on a dense list,
// then create holes at the end.
var denseList = new List();
var denseLen = 0;
for (var i = 0; i < len; i++) {
if (i in array)
denseList[denseLen++] = array[i];
@ -253,7 +253,7 @@ function MergeSort(array, len, comparefn) {
// Insertion sort for small arrays, where "small" is defined by performance
// testing.
if (len < 24) {
if (denseLen < 24) {
InsertionSort(denseList, 0, denseLen - 1, comparefn);
MoveHoles(array, len, denseList, denseLen);
return array;