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:
parent
9b61322e02
commit
578ffe1edb
@ -86,8 +86,8 @@ function makeRequireFunction(mod, redirects) {
|
|||||||
if (destination === true) {
|
if (destination === true) {
|
||||||
missing = false;
|
missing = false;
|
||||||
} else if (destination) {
|
} else if (destination) {
|
||||||
const href = destination.href;
|
const { href, protocol } = destination;
|
||||||
if (destination.protocol === 'node:') {
|
if (protocol === 'node:') {
|
||||||
const specifier = destination.pathname;
|
const specifier = destination.pathname;
|
||||||
|
|
||||||
if (BuiltinModule.canBeRequiredByUsers(specifier)) {
|
if (BuiltinModule.canBeRequiredByUsers(specifier)) {
|
||||||
@ -95,11 +95,9 @@ function makeRequireFunction(mod, redirects) {
|
|||||||
return mod.exports;
|
return mod.exports;
|
||||||
}
|
}
|
||||||
throw new ERR_UNKNOWN_BUILTIN_MODULE(specifier);
|
throw new ERR_UNKNOWN_BUILTIN_MODULE(specifier);
|
||||||
} else if (destination.protocol === 'file:') {
|
} else if (protocol === 'file:') {
|
||||||
let filepath;
|
let filepath = urlToFileCache.get(href);
|
||||||
if (urlToFileCache.has(href)) {
|
if (!filepath) {
|
||||||
filepath = urlToFileCache.get(href);
|
|
||||||
} else {
|
|
||||||
filepath = fileURLToPath(destination);
|
filepath = fileURLToPath(destination);
|
||||||
urlToFileCache.set(href, filepath);
|
urlToFileCache.set(href, filepath);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user