Skip to content

Commit

Permalink
module: reduce require syscalls
Browse files Browse the repository at this point in the history
During require search, check the path exists before searching further in it.
  • Loading branch information
pierreinglebert committed Jun 11, 2015
1 parent 4b3d493 commit a10ce67
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 a10ce67

Please sign in to comment.