Skip to content

Commit

Permalink
module: reduce syscalls during require search
Browse files Browse the repository at this point in the history
require() now checks that the path exists before searching
further in it.

PR-URL: #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>
  • Loading branch information
pierreinglebert authored and Fishrock123 committed Jun 18, 2015
1 parent 061342a commit a71ee93
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [''];
}

Expand All @@ -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;

Expand Down

0 comments on commit a71ee93

Please sign in to comment.