Browse Source

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>
v5.x
Andres Suarez 9 years ago
committed by Myles Borins
parent
commit
145b66820f
  1. 7
      lib/module.js

7
lib/module.js

@ -126,19 +126,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…
Cancel
Save