From fd3f89a87a36abd242d8462c9e818ebdc44f7229 Mon Sep 17 00:00:00 2001 From: cjihrig Date: Tue, 18 Apr 2017 21:01:48 -0400 Subject: [PATCH] events: remove unreachable code Commit 8d386ed7e1301c869bbc266ce73650b280c9ae26 stopped the Event Emitter implementation from storing arrays containing a single listener. This change left a section of code in removeListener() as unreachable. This commit removes the unreachable code. Refs: https://github.com/nodejs/node/pull/12043 PR-URL: https://github.com/nodejs/node/pull/12501 Backport-PR-URL: https://github.com/nodejs/node/pull/13796 Reviewed-By: Luigi Pinca Reviewed-By: James M Snell --- lib/events.js | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/lib/events.js b/lib/events.js index 5daa2e82f3e066..c025be64f9f9ef 100644 --- a/lib/events.js +++ b/lib/events.js @@ -349,22 +349,13 @@ EventEmitter.prototype.removeListener = if (position < 0) return this; - if (list.length === 1) { - if (--this._eventsCount === 0) { - this._events = new EventHandlers(); - return this; - } else { - delete events[type]; - } - } else if (position === 0) { + if (position === 0) list.shift(); - if (list.length === 1) - events[type] = list[0]; - } else { + else spliceOne(list, position); - if (list.length === 1) - events[type] = list[0]; - } + + if (list.length === 1) + events[type] = list[0]; if (events.removeListener) this.emit('removeListener', type, originalListener || listener);