events: cache `domain` module locally
authorMaciej Małecki <maciej.malecki@notimplemented.org>
Sun, 17 Jun 2012 09:50:40 +0000 (11:50 +0200)
committerisaacs <i@izs.me>
Sun, 17 Jun 2012 20:07:20 +0000 (13:07 -0700)
It's faster than calling `require` every time we create an
`EventEmitter`.

lib/events.js

index fe7c048..7e219a1 100644 (file)
 // USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 var isArray = Array.isArray;
+var domain;
 
 function EventEmitter() {
   if (exports.usingDomains) {
     // if there is an active domain, then attach to it.
-    var domain = require('domain');
+    domain = domain || require('domain');
     if (domain.active && !(this instanceof domain.Domain)) {
       this.domain = domain.active;
     }