Skip to content

Commit

Permalink
events: improve removeListener() performance
Browse files Browse the repository at this point in the history
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: #10572
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
  • Loading branch information
mscdex authored and italoacasas committed Jan 27, 2017
1 parent 2f4577c commit ded1757
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,8 @@ EventEmitter.prototype.removeListener =
} else {
delete events[type];
}
} else if (position === 0) {
list.shift();
} else {
spliceOne(list, position);
}
Expand Down

0 comments on commit ded1757

Please sign in to comment.