Skip to content

Commit

Permalink
events: optimize arrayClone by copying forward
Browse files Browse the repository at this point in the history
Optimize arrayClone by copying forward.

It's slightly faster (and more readable) to copy array elements
in forward direction. This way it also avoids the ToBoolean and
the postfix count operation.

PR-URL: nodejs#10571
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
  • Loading branch information
bmeurer authored and fhinkel committed Jan 4, 2017
1 parent 4198253 commit f2f997a
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -477,9 +477,9 @@ function spliceOne(list, index) {
list.pop();
}

function arrayClone(arr, i) {
var copy = new Array(i);
while (i--)
function arrayClone(arr, n) {
var copy = new Array(n);
for (var i = 0; i < n; ++i)
copy[i] = arr[i];
return copy;
}
Expand Down

0 comments on commit f2f997a

Please sign in to comment.