Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 32bda81

Browse filesBrowse 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
Copy full SHA for 32bda81

File tree

Expand file treeCollapse file tree

1 file changed

+5
-7
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+5
-7
lines changed
Open diff view settings
Collapse file

‎lib/internal/modules/helpers.js‎

Copy file name to clipboardExpand all lines: lib/internal/modules/helpers.js
+5-7Lines changed: 5 additions & 7 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.