Permalink
Browse files

events: optimize arrayClone by copying forward

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: #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...
1 parent dcc20f1 commit 66a9f013ac7d2c2c6c0b05f87c924f631bf36939 @bmeurer bmeurer committed with evanlucas Jan 2, 2017
Showing with 3 additions and 3 deletions.
  1. +3 −3 lib/events.js
View
@@ -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;
}

0 comments on commit 66a9f01

Please sign in to comment.