Comparing version 0.0.5 to 0.0.6
@@ -9,3 +9,3 @@ #!/usr/bin/env node | ||
var bench = require('visualbench')( EV.version + ':emit:' + listenersNum ) | ||
var bench = require('visualbench')( 'emit:' + listenersNum, EV.version ) | ||
@@ -12,0 +12,0 @@ function test () { |
@@ -0,1 +1,7 @@ | ||
0.0.6 / 2012-03-08 | ||
================== | ||
* Added stack trace to the 'Warning: undefined event...' message | ||
* Mitigated performance regression due to scope setting | ||
0.0.5 / 2012-03-07 | ||
@@ -2,0 +8,0 @@ ================== |
110
lib/ev.js
@@ -79,6 +79,7 @@ var maxListeners = 10 | ||
console.error( | ||
'Warning (EventEmitter): undefined event [%s]. ' + | ||
'Define at EventEmitter instanciation for better performance.' | ||
'Warning (EventEmitter): undefined event [%s]. ' | ||
+ 'Define at EventEmitter instanciation for better performance.' | ||
, ev | ||
) | ||
console.trace() | ||
} | ||
@@ -109,5 +110,5 @@ | ||
console.error( | ||
'Warning (EventEmitter): Possible EventEmitter memory ' + | ||
'leak detected. %d listeners added to event %s. ' + | ||
'Use emitter.setMaxListeners() to increase limit.' | ||
'Warning (EventEmitter): Possible EventEmitter memory ' | ||
+ 'leak detected. %d listeners added to event %s. ' | ||
+ 'Use emitter.setMaxListeners() to increase limit.' | ||
, n | ||
@@ -129,32 +130,71 @@ , ev | ||
// Additional listener, register it according to its # of arguments | ||
switch ( this._ev_length[ev] ) { | ||
case 0: | ||
this._ev_emit[ev] = this[key] = function () { | ||
fn.call(self) | ||
handler.call(self) | ||
} | ||
break | ||
case 1: | ||
this._ev_emit[ev] = this[key] = function () { | ||
fn.call(self, arguments[0]) | ||
handler.call(self, arguments[0]) | ||
} | ||
break | ||
case 2: | ||
this._ev_emit[ev] = this[key] = function () { | ||
fn.call(self, arguments[0], arguments[1]) | ||
handler.call(self, arguments[0], arguments[1]) | ||
} | ||
break | ||
case 3: | ||
this._ev_emit[ev] = this[key] = function () { | ||
fn.call(self, arguments[0], arguments[1], arguments[2]) | ||
handler.call(self, arguments[0], arguments[1], arguments[2]) | ||
} | ||
break | ||
default: | ||
this._ev_emit[ev] = this[key] = function () { | ||
fn.apply(self, arguments) | ||
handler.apply(self, arguments) | ||
} | ||
if (n === 1) { | ||
// fn = first handler | ||
// handler = second handler | ||
// -> need to apply the scope to both | ||
switch ( this._ev_length[ev] ) { | ||
case 0: | ||
this._ev_emit[ev] = this[key] = function () { | ||
fn.call(self) | ||
handler.call(self) | ||
} | ||
break | ||
case 1: | ||
this._ev_emit[ev] = this[key] = function () { | ||
fn.call(self, arguments[0]) | ||
handler.call(self, arguments[0]) | ||
} | ||
break | ||
case 2: | ||
this._ev_emit[ev] = this[key] = function () { | ||
fn.call(self, arguments[0], arguments[1]) | ||
handler.call(self, arguments[0], arguments[1]) | ||
} | ||
break | ||
case 3: | ||
this._ev_emit[ev] = this[key] = function () { | ||
fn.call(self, arguments[0], arguments[1], arguments[2]) | ||
handler.call(self, arguments[0], arguments[1], arguments[2]) | ||
} | ||
break | ||
default: | ||
this._ev_emit[ev] = this[key] = function () { | ||
fn.apply(self, arguments) | ||
handler.apply(self, arguments) | ||
} | ||
} | ||
} else { | ||
// Scope already set for the handlers triggered by fn | ||
// -> no need to set fn's scope | ||
switch ( this._ev_length[ev] ) { | ||
case 0: | ||
this._ev_emit[ev] = this[key] = function () { | ||
fn() | ||
handler.call(self) | ||
} | ||
break | ||
case 1: | ||
this._ev_emit[ev] = this[key] = function () { | ||
fn(arguments[0]) | ||
handler.call(self, arguments[0]) | ||
} | ||
break | ||
case 2: | ||
this._ev_emit[ev] = this[key] = function () { | ||
fn(arguments[0], arguments[1]) | ||
handler.call(self, arguments[0], arguments[1]) | ||
} | ||
break | ||
case 3: | ||
this._ev_emit[ev] = this[key] = function () { | ||
fn(arguments[0], arguments[1], arguments[2]) | ||
handler.call(self, arguments[0], arguments[1], arguments[2]) | ||
} | ||
break | ||
default: | ||
this._ev_emit[ev] = this[key] = function () { | ||
fn(arguments) | ||
handler.apply(self, arguments) | ||
} | ||
} | ||
} | ||
@@ -161,0 +201,0 @@ return this |
@@ -6,3 +6,3 @@ { | ||
, "keywords": ["event","emitter","listener"] | ||
, "version": "0.0.5" | ||
, "version": "0.0.6" | ||
, "homepage": "http://github.com/pierrec/node-ev" | ||
@@ -9,0 +9,0 @@ , "repository": { |
# TODO | ||
* Performance regression 0.0.4 -> 0.0.5 caused by .call() |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
169220
30
1256