Skip to content

Commit a71ee93

Browse files
pierreinglebertFishrock123
authored andcommitted
module: reduce syscalls during require search
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>
1 parent 061342a commit a71ee93

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

lib/module.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ const noopDeprecateRequireDot = util.deprecate(function() {},
129129
Module._findPath = function(request, paths) {
130130
var exts = Object.keys(Module._extensions);
131131

132-
if (request.charAt(0) === '/') {
132+
if (path.isAbsolute(request)) {
133133
paths = [''];
134134
}
135135

@@ -142,6 +142,8 @@ Module._findPath = function(request, paths) {
142142

143143
// For each path
144144
for (var i = 0, PL = paths.length; i < PL; i++) {
145+
// Don't search further if path doesn't exist
146+
if (paths[i] && internalModuleStat(paths[i]) < 1) continue;
145147
var basePath = path.resolve(paths[i], request);
146148
var filename;
147149

0 commit comments

Comments
 (0)