From aab1dd6ff4a30191f36d6a7ed3fd7e47477dd2fb Mon Sep 17 00:00:00 2001 From: Brian White Date: Mon, 2 Jan 2017 03:17:21 -0500 Subject: [PATCH] events: improve removeListener() performance array.shift() seems to be faster than arrayClone() when the item to remove is at the front (at least with V8 5.4). PR-URL: https://github.com/nodejs/node/pull/10572 Reviewed-By: Benjamin Gruenbaum Reviewed-By: James M Snell Reviewed-By: Michael Dawson --- lib/events.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/events.js b/lib/events.js index 6a8345ab7bc516..209700e65ad596 100644 --- a/lib/events.js +++ b/lib/events.js @@ -360,6 +360,8 @@ EventEmitter.prototype.removeListener = } else { delete events[type]; } + } else if (position === 0) { + list.shift(); } else { spliceOne(list, position); }