Skip to content

Commit 66a9f01

Browse files
bmeurerevanlucas
authored andcommitted
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>
1 parent dcc20f1 commit 66a9f01

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

lib/events.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -477,9 +477,9 @@ function spliceOne(list, index) {
477477
list.pop();
478478
}
479479

480-
function arrayClone(arr, i) {
481-
var copy = new Array(i);
482-
while (i--)
480+
function arrayClone(arr, n) {
481+
var copy = new Array(n);
482+
for (var i = 0; i < n; ++i)
483483
copy[i] = arr[i];
484484
return copy;
485485
}

0 commit comments

Comments
 (0)