Skip to content

Commit

Permalink
events: improve listeners() performance
Browse files Browse the repository at this point in the history
PR-URL: #33863
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
  • Loading branch information
mscdex authored and jasnell committed Jun 17, 2020
1 parent 272b46e commit a4f3206
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion benchmark/events/ee-listeners.js
Expand Up @@ -14,7 +14,7 @@ function main({ n, listeners, raw }) {

for (let k = 0; k < listeners; k += 1) {
ee.on('dummy0', () => {});
ee.on('dummy1', () => {});
ee.once('dummy1', () => {});
}

if (raw === 'true') {
Expand Down
7 changes: 4 additions & 3 deletions lib/events.js
Expand Up @@ -22,7 +22,6 @@
'use strict';

const {
Array,
Boolean,
Error,
MathMin,
Expand Down Expand Up @@ -613,9 +612,11 @@ function arrayClone(arr) {
}

function unwrapListeners(arr) {
const ret = new Array(arr.length);
const ret = arrayClone(arr);
for (let i = 0; i < ret.length; ++i) {
ret[i] = arr[i].listener || arr[i];
const orig = ret[i].listener;
if (typeof orig === 'function')
ret[i] = orig;
}
return ret;
}
Expand Down

0 comments on commit a4f3206

Please sign in to comment.