Skip to content

Commit

Permalink
events: loop backwards in removeListener
Browse files Browse the repository at this point in the history
`removeAllListeners` is removing events from end to start. Therefore
it spends O(n^2) time, since `removeListener` is searching from start to
end.
  • Loading branch information
fb55 authored and indutny committed Mar 5, 2013
1 parent d09ab61 commit 3e64b56
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ EventEmitter.prototype.removeListener = function(type, listener) {
this.emit('removeListener', type, listener);

} else if (typeof list === 'object') {
for (i = 0; i < length; i++) {
for (i = length; i-- > 0;) {
if (list[i] === listener ||
(list[i].listener && list[i].listener === listener)) {
position = i;
Expand Down

0 comments on commit 3e64b56

Please sign in to comment.