Skip to content

Commit

Permalink
[fixup] tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
apapirovski committed Nov 21, 2017
1 parent b958ba3 commit 4f0465c
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 21 deletions.
2 changes: 1 addition & 1 deletion benchmark/events/ee-add-remove.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
const common = require('../common.js');
const events = require('events');

const bench = common.createBenchmark(main, { n: [25e4] });
const bench = common.createBenchmark(main, { n: [5e6] });

function main(conf) {
const n = conf.n | 0;
Expand Down
2 changes: 1 addition & 1 deletion benchmark/events/ee-emit.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const common = require('../common.js');
const EventEmitter = require('events').EventEmitter;

const bench = common.createBenchmark(main, {
n: [2e6],
n: [2e7],
argc: [0, 2, 4, 10],
listeners: [1, 5, 10],
});
Expand Down
2 changes: 1 addition & 1 deletion benchmark/events/ee-listeners-many.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
const common = require('../common.js');
const EventEmitter = require('events').EventEmitter;

const bench = common.createBenchmark(main, { n: [5e6] });
const bench = common.createBenchmark(main, { n: [1e7] });

function main(conf) {
const n = conf.n | 0;
Expand Down
2 changes: 1 addition & 1 deletion benchmark/events/ee-listeners.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
const common = require('../common.js');
const EventEmitter = require('events').EventEmitter;

const bench = common.createBenchmark(main, { n: [5e6] });
const bench = common.createBenchmark(main, { n: [5e7] });

function main(conf) {
const n = conf.n | 0;
Expand Down
26 changes: 9 additions & 17 deletions lib/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,13 +375,9 @@ EventEmitter.prototype.removeListener =
return this;

if (list === listener || list.listener === listener) {
if (events.size === 1)
this[kEvents] = undefined;
else {
events.delete(type);
if (events.has('removeListener'))
this.emit('removeListener', type, list.listener || listener);
}
events.delete(type);
if (events.size && events.has('removeListener'))
this.emit('removeListener', type, list.listener || listener);
return this;
}

Expand Down Expand Up @@ -434,14 +430,10 @@ EventEmitter.prototype.removeAllListeners =

// not listening for removeListener, no need to emit
if (!events.has('removeListener')) {
if (arguments.length === 0) {
this[kEvents] = undefined;
} else if (events.has(type)) {
if (events.size === 1)
this[kEvents] = undefined;
else
events.delete(type);
}
if (arguments.length === 0)
this[kEvents] = new Map();
else
events.delete(type);
return this;
}

Expand All @@ -454,7 +446,7 @@ EventEmitter.prototype.removeAllListeners =
this.removeAllListeners(key);
}
this.removeAllListeners('removeListener');
this[kEvents] = undefined;
this[kEvents] = new Map();
return this;
}

Expand All @@ -475,7 +467,7 @@ EventEmitter.prototype.removeAllListeners =
EventEmitter.prototype.listeners = function listeners(type, unwrap = true) {
const events = this[kEvents];

if (events === undefined)
if (events === undefined || !events.size)
return [];

const evlistener = events.get(type);
Expand Down

0 comments on commit 4f0465c

Please sign in to comment.