Skip to content

Commit

Permalink
module: move unnecessary work for early return
Browse files Browse the repository at this point in the history
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 <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>
  • Loading branch information
zertosh authored and Myles Borins committed Feb 15, 2016
1 parent aefb20a commit 2e92a1a
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions lib/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2e92a1a

Please sign in to comment.