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: https://github.com/nodejs/node/pull/3579 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Trevor Norris <trev.norris@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michaël Zasso <mic.besace@gmail.com>
This commit is contained in:
parent
521f51ac1c
commit
1285671283
@ -136,19 +136,18 @@ function tryExtensions(p, exts) {
|
||||
|
||||
var warned = false;
|
||||
Module._findPath = function(request, paths) {
|
||||
var exts = Object.keys(Module._extensions);
|
||||
|
||||
if (path.isAbsolute(request)) {
|
||||
paths = [''];
|
||||
}
|
||||
|
||||
var trailingSlash = (request.slice(-1) === '/');
|
||||
|
||||
var cacheKey = JSON.stringify({request: request, paths: paths});
|
||||
if (Module._pathCache[cacheKey]) {
|
||||
return Module._pathCache[cacheKey];
|
||||
}
|
||||
|
||||
const exts = Object.keys(Module._extensions);
|
||||
const trailingSlash = request.slice(-1) === '/';
|
||||
|
||||
// For each path
|
||||
for (var i = 0, PL = paths.length; i < PL; i++) {
|
||||
// Don't search further if path doesn't exist
|
||||
|
Loading…
x
Reference in New Issue
Block a user