From f2f997ad1e416fd5ba295e84139848f77b37c40f Mon Sep 17 00:00:00 2001 From: Benedikt Meurer Date: Mon, 2 Jan 2017 07:20:57 +0100 Subject: 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 Reviewed-By: Benjamin Gruenbaum Reviewed-By: Rich Trott Reviewed-By: Colin Ihrig Reviewed-By: James M Snell Reviewed-By: Franziska Hinkelmann --- lib/events.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/events.js') 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; } -- cgit v1.2.3