perf(orderBy): copy array with slice instead of for loop

Use array slice method to copy entire array instead of a for loop
http://jsperf.com/new-array-vs-splice-vs-slice/54

Closes #9942
This commit is contained in:
Karol Wypchło
2014-11-06 15:07:21 +01:00
committed by Caitlin Potter
parent e49a1433fd
commit 409bcb3810

View File

@@ -146,9 +146,7 @@ function orderByFilter($parse){
return compare(get(a),get(b));
}, descending);
});
var arrayCopy = [];
for ( var i = 0; i < array.length; i++) { arrayCopy.push(array[i]); }
return arrayCopy.sort(reverseComparator(comparator, reverseOrder));
return slice.call(array).sort(reverseComparator(comparator, reverseOrder));
function comparator(o1, o2){
for ( var i = 0; i < sortPredicate.length; i++) {