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 <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Gerhard Stöbich <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Yongsheng Zhang <[email protected]>
  • Loading branch information
mscdex authored and addaleax committed Sep 21, 2020
1 parent e4854de commit ff7fbc3
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
'use strict';

const {
Array,
Boolean,
Error,
MathMin,
Expand Down Expand Up @@ -616,9 +615,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 ff7fbc3

Please sign in to comment.