Skip to content
This repository was archived by the owner on Apr 22, 2023. It is now read-only.

Commit e4d4c98

Browse files
committed
Use given args instead of arguments object.
This speeds up argument access when there are 1 or 2 event arguments.
1 parent cfcb1de commit e4d4c98

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

lib/events.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ EventEmitter.prototype.setMaxListeners = function setMaxListeners(n) {
6565
return this;
6666
};
6767

68-
EventEmitter.prototype.emit = function emit(type) {
68+
EventEmitter.prototype.emit = function emit(type, arg1, arg2) {
6969
var er, handler, len, args, i, listeners;
7070

7171
if (!this._events)
@@ -97,28 +97,27 @@ EventEmitter.prototype.emit = function emit(type) {
9797
if (this.domain && this !== process)
9898
this.domain.enter();
9999

100+
len = arguments.length;
100101
if (util.isFunction(handler)) {
101-
switch (arguments.length) {
102+
switch (len) {
102103
// fast cases
103104
case 1:
104105
handler.call(this);
105106
break;
106107
case 2:
107-
handler.call(this, arguments[1]);
108+
handler.call(this, arg1);
108109
break;
109110
case 3:
110-
handler.call(this, arguments[1], arguments[2]);
111+
handler.call(this, arg1, arg2);
111112
break;
112113
// slower
113114
default:
114-
len = arguments.length;
115115
args = new Array(len - 1);
116116
for (i = 1; i < len; i++)
117117
args[i - 1] = arguments[i];
118118
handler.apply(this, args);
119119
}
120120
} else if (util.isObject(handler)) {
121-
len = arguments.length;
122121
args = new Array(len - 1);
123122
for (i = 1; i < len; i++)
124123
args[i - 1] = arguments[i];

0 commit comments

Comments
 (0)