From 66a9f013ac7d2c2c6c0b05f87c924f631bf36939 Mon Sep 17 00:00:00 2001 From: Benedikt Meurer Date: Mon, 2 Jan 2017 07:20:57 +0100 Subject: [PATCH] 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(-) 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; }