events: loop backwards in removeListener

`removeAllListeners` is removing events from end to start. Therefore
it spends O(n^2) time, since `removeListener` is searching from start to
end.
pull/24507/merge
Felix Böhm 2013-03-05 09:20:23 +01:00 committed by Fedor Indutny
parent d09ab61dcd
commit 3e64b5677f
1 changed files with 1 additions and 1 deletions

View File

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