summaryrefslogtreecommitdiff
path: root/lib/module.js
diff options
context:
space:
mode:
authorBrian White <mscdex@mscdex.net>2017-01-13 05:13:53 -0500
committerBrian White <mscdex@mscdex.net>2017-03-10 23:48:41 -0500
commit403b89e72b6367934ca3c36d389ce0f3214ffbf5 (patch)
treeddda88ad1b30cddba33bab446bef1c183a402a41 /lib/module.js
parent298a40e04ee496dbd6b2324a20d9ff745fef74cb (diff)
downloadandroid-node-v8-403b89e72b6367934ca3c36d389ce0f3214ffbf5.tar.gz
android-node-v8-403b89e72b6367934ca3c36d389ce0f3214ffbf5.tar.bz2
android-node-v8-403b89e72b6367934ca3c36d389ce0f3214ffbf5.zip
module: avoid hasOwnProperty()
hasOwnProperty() is known to be slow, do a direct lookup on a "clean" object instead. PR-URL: https://github.com/nodejs/node/pull/10789 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michaƫl Zasso <targos@protonmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Diffstat (limited to 'lib/module.js')
-rw-r--r--lib/module.js16
1 files changed, 4 insertions, 12 deletions
diff --git a/lib/module.js b/lib/module.js
index bd6af190f6..8916b3b36c 100644
--- a/lib/module.js
+++ b/lib/module.js
@@ -33,14 +33,6 @@ const internalModuleReadFile = process.binding('fs').internalModuleReadFile;
const internalModuleStat = process.binding('fs').internalModuleStat;
const preserveSymlinks = !!process.binding('config').preserveSymlinks;
-// If obj.hasOwnProperty has been overridden, then calling
-// obj.hasOwnProperty(prop) will break.
-// See: https://github.com/joyent/node/issues/1707
-function hasOwnProperty(obj, prop) {
- return Object.prototype.hasOwnProperty.call(obj, prop);
-}
-
-
function stat(filename) {
filename = path._makeLong(filename);
const cache = stat.cache;
@@ -95,12 +87,12 @@ const debug = Module._debug;
// -> a/index.<ext>
// check if the directory is a package.json dir
-const packageMainCache = {};
+const packageMainCache = Object.create(null);
function readPackage(requestPath) {
- if (hasOwnProperty(packageMainCache, requestPath)) {
- return packageMainCache[requestPath];
- }
+ const entry = packageMainCache[requestPath];
+ if (entry)
+ return entry;
const jsonPath = path.resolve(requestPath, 'package.json');
const json = internalModuleReadFile(path._makeLong(jsonPath));