Skip to content

Commit 32bda81

Browse files
anonrigRafaelGSS
authored andcommitted
lib: reduce url getters on makeRequireFunction
PR-URL: #48492 Refs: nodejs/performance#92 Reviewed-By: Jacob Smith <jacob@frende.me> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 417927b commit 32bda81

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

lib/internal/modules/helpers.js

+5-7
Original file line numberDiff line numberDiff line change
@@ -86,20 +86,18 @@ function makeRequireFunction(mod, redirects) {
8686
if (destination === true) {
8787
missing = false;
8888
} else if (destination) {
89-
const href = destination.href;
90-
if (destination.protocol === 'node:') {
89+
const { href, protocol } = destination;
90+
if (protocol === 'node:') {
9191
const specifier = destination.pathname;
9292

9393
if (BuiltinModule.canBeRequiredByUsers(specifier)) {
9494
const mod = loadBuiltinModule(specifier, href);
9595
return mod.exports;
9696
}
9797
throw new ERR_UNKNOWN_BUILTIN_MODULE(specifier);
98-
} else if (destination.protocol === 'file:') {
99-
let filepath;
100-
if (urlToFileCache.has(href)) {
101-
filepath = urlToFileCache.get(href);
102-
} else {
98+
} else if (protocol === 'file:') {
99+
let filepath = urlToFileCache.get(href);
100+
if (!filepath) {
103101
filepath = fileURLToPath(destination);
104102
urlToFileCache.set(href, filepath);
105103
}

0 commit comments

Comments
 (0)