summaryrefslogtreecommitdiff
path: root/lib/events.js
diff options
context:
space:
mode:
authorBenedikt Meurer <bmeurer@google.com>2017-01-02 07:20:57 +0100
committerFranziska Hinkelmann <franzih@chromium.org>2017-01-04 14:56:41 +0100
commitf2f997ad1e416fd5ba295e84139848f77b37c40f (patch)
tree1b52908fda07a5c6eceb48eab89a45b405a33518 /lib/events.js
parent4198253a185e20b7a9d0fb363fabacece712200d (diff)
downloadnode-new-f2f997ad1e416fd5ba295e84139848f77b37c40f.tar.gz
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: https://github.com/nodejs/node/pull/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>
Diffstat (limited to 'lib/events.js')
-rw-r--r--lib/events.js6
1 files changed, 3 insertions, 3 deletions
diff --git a/lib/events.js b/lib/events.js
index 4ccec4e595..6a8345ab7b 100644
--- a/lib/events.js
+++ b/lib/events.js
@@ -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;
}