startup: use `.hasOwnProperty` instead of `in`
authorMaciej Małecki <maciej.malecki@notimplemented.org>
Sat, 18 Feb 2012 15:32:06 +0000 (16:32 +0100)
committerBen Noordhuis <info@bnoordhuis.nl>
Mon, 20 Feb 2012 15:04:44 +0000 (16:04 +0100)
Benchmarks show that `.hasOwnProperty` is faster than `in` in V8. It
makes startup ~0.5 ms faster on my computer.

src/node.js

index e73eb18..2cd797f 100644 (file)
   }
 
   NativeModule.exists = function(id) {
-    return (id in NativeModule._source);
+    return NativeModule._source.hasOwnProperty(id);
   }
 
   NativeModule.getSource = function(id) {