Skip to content

Commit 5d682c5

Browse files
anonrigruyadorno
authored andcommittedSep 12, 2023
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 e2f3ed1 commit 5d682c5

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed
 

‎lib/internal/modules/cjs/helpers.js

+5-7
Original file line numberDiff line numberDiff line change
@@ -87,19 +87,17 @@ function makeRequireFunction(mod, redirects) {
8787
if (destination === true) {
8888
missing = false;
8989
} else if (destination) {
90-
const href = destination.href;
91-
if (destination.protocol === 'node:') {
90+
const { href, protocol } = destination;
91+
if (protocol === 'node:') {
9292
const specifier = destination.pathname;
9393
const mod = loadBuiltinModule(specifier, href);
9494
if (mod && mod.canBeRequiredByUsers) {
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)
Please sign in to comment.