Skip to content

Commit 1285671

Browse files
zertoshcjihrig
authored andcommitted
module: move unnecessary work for early return
The exts and trailingSlash variables are only used if the path isn't cached. This commit moves them further down in the code, and changes from var to const. PR-URL: #3579 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Trevor Norris <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Michaël Zasso <[email protected]>
1 parent 521f51a commit 1285671

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

lib/module.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -136,19 +136,18 @@ function tryExtensions(p, exts) {
136136

137137
var warned = false;
138138
Module._findPath = function(request, paths) {
139-
var exts = Object.keys(Module._extensions);
140-
141139
if (path.isAbsolute(request)) {
142140
paths = [''];
143141
}
144142

145-
var trailingSlash = (request.slice(-1) === '/');
146-
147143
var cacheKey = JSON.stringify({request: request, paths: paths});
148144
if (Module._pathCache[cacheKey]) {
149145
return Module._pathCache[cacheKey];
150146
}
151147

148+
const exts = Object.keys(Module._extensions);
149+
const trailingSlash = request.slice(-1) === '/';
150+
152151
// For each path
153152
for (var i = 0, PL = paths.length; i < PL; i++) {
154153
// Don't search further if path doesn't exist

0 commit comments

Comments
 (0)