mirror of https://github.com/nodejs/node.git
Optimize for few args in EventEmitter.emit
parent
6abdf051d3
commit
0633e5cac9
|
@ -2,7 +2,8 @@ exports.EventEmitter = process.EventEmitter;
|
||||||
|
|
||||||
|
|
||||||
process.EventEmitter.prototype.emit = function (type) {
|
process.EventEmitter.prototype.emit = function (type) {
|
||||||
if (type == 'error') {
|
// If there is no 'error' event listener then throw.
|
||||||
|
if (type === 'error') {
|
||||||
if (!this._events || !this._events.error ||
|
if (!this._events || !this._events.error ||
|
||||||
(this._events.error instanceof Array && !this._events.error.length))
|
(this._events.error instanceof Array && !this._events.error.length))
|
||||||
{
|
{
|
||||||
|
@ -19,9 +20,17 @@ process.EventEmitter.prototype.emit = function (type) {
|
||||||
if (!this._events[type]) return false;
|
if (!this._events[type]) return false;
|
||||||
|
|
||||||
if (typeof this._events[type] == 'function') {
|
if (typeof this._events[type] == 'function') {
|
||||||
var args = Array.prototype.slice.call(arguments, 1);
|
if (arguments.length < 3) {
|
||||||
|
// fast case
|
||||||
this._events[type].apply(this, args);
|
this._events[type].call( this
|
||||||
|
, arguments[1]
|
||||||
|
, arguments[2]
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
// slower
|
||||||
|
var args = Array.prototype.slice.call(arguments, 1);
|
||||||
|
this._events[type].apply(this, args);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
} else if (this._events[type] instanceof Array) {
|
} else if (this._events[type] instanceof Array) {
|
||||||
|
|
Loading…
Reference in New Issue