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);