module: reduce syscalls during require search

require() now checks that the path exists before searching
further in it.

PR-URL: https://github.com/nodejs/io.js/pull/1920
Reviewed-By: Isaac Z. Schlueter <i@izs.me>
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
Reviewed-By: Chris Dickinson <christopher.s.dickinson@gmail.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
This commit is contained in:
Pierre Inglebert authored and Jeremiah Senkpiel committed 2015-06-17 17:24:29 -07:00
1 parent 061342a500
commit a71ee93afe
1 file changed
+3 -1
+3 -1
View File
@@ -129,7 +129,7 @@ const noopDeprecateRequireDot = util.deprecate(function() {},
Module._findPath = function(request, paths) {
var exts = Object.keys(Module._extensions);
if (request.charAt(0) === '/') {
if (path.isAbsolute(request)) {
paths = [''];
}
@@ -142,6 +142,8 @@ Module._findPath = function(request, paths) {
// For each path
for (var i = 0, PL = paths.length; i < PL; i++) {
// Don't search further if path doesn't exist
if (paths[i] && internalModuleStat(paths[i]) < 1) continue;
var basePath = path.resolve(paths[i], request);
var filename;