lib: reduce url getters on makeRequireFunction

PR-URL: https://github.com/nodejs/node/pull/48492
Refs: https://github.com/nodejs/performance/issues/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>
This commit is contained in:
Yagiz Nizipli 2023-06-23 20:33:22 -04:00 committed by GitHub
parent 9b61322e02
commit 578ffe1edb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -86,8 +86,8 @@ function makeRequireFunction(mod, redirects) {
if (destination === true) {
missing = false;
} else if (destination) {
const href = destination.href;
if (destination.protocol === 'node:') {
const { href, protocol } = destination;
if (protocol === 'node:') {
const specifier = destination.pathname;
if (BuiltinModule.canBeRequiredByUsers(specifier)) {
@ -95,11 +95,9 @@ function makeRequireFunction(mod, redirects) {
return mod.exports;
}
throw new ERR_UNKNOWN_BUILTIN_MODULE(specifier);
} else if (destination.protocol === 'file:') {
let filepath;
if (urlToFileCache.has(href)) {
filepath = urlToFileCache.get(href);
} else {
} else if (protocol === 'file:') {
let filepath = urlToFileCache.get(href);
if (!filepath) {
filepath = fileURLToPath(destination);
urlToFileCache.set(href, filepath);
}