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: nodejs#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]>
  • Loading branch information
zertosh authored and Michael Scovetta committed Apr 2, 2016
1 parent 0612770 commit 77dceb4
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 @@ -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
Expand Down

0 comments on commit 77dceb4

Please sign in to comment.