-
Notifications
You must be signed in to change notification settings - Fork 27.4k
perf(orderBy): copy array with slice instead of for loop #9942
Conversation
var arrayCopy = []; | ||
for (var i = 0; i < array.length; i++) { arrayCopy.push(array[i]); } | ||
return arrayCopy.sort(reverseComparator(comparator, reverseOrder)); | ||
return array.slice().sort(reverseComparator(comparator, reverseOrder)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem with this is that array
is not necessarlly an Array. it can be an array-like object. This only works in the Array case.
Can you make sure that this will work with ArrayLike objects (with a test case) and ping me when it's ready? |
I'm afraid it doesn't work with ArrayLike object
|
Note that a reference to
|
Sure, I'm going back from vacations tomorrow and I will apply the changes :) |
Use array slice method to copy entire array instead of a for loop http://jsperf.com/new-array-vs-splice-vs-slice/54
1cd391d
to
3024501
Compare
@caitp I've amended the commit to include what @jimmywarting and @gkalpak were suggesting as a fix for array like objects. It looks fine now and it works as expected. |
looks ok to me, will land in a few minutes |
Use array slice method to copy entire array instead of a for loop http://jsperf.com/new-array-vs-splice-vs-slice/54 Closes angular#9942
Use array slice method to copy entire array instead of a for loop
http://jsperf.com/new-array-vs-splice-vs-slice/54