From 145b66820f943e2e9885f7b70706c6d6818e5784 Mon Sep 17 00:00:00 2001 From: Andres Suarez Date: Wed, 28 Oct 2015 20:09:38 -0700 Subject: [PATCH] module: move unnecessary work for early return MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-By: Trevor Norris Reviewed-By: James M Snell Reviewed-By: Michaƫl Zasso --- lib/module.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/module.js b/lib/module.js index 8feba15b0f..8dd304e85e 100644 --- a/lib/module.js +++ b/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