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 <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Geoffrey Booth <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]>
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‎

Lines 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
}elseif(destination){
89-
consthref=destination.href;
90-
if(destination.protocol==='node:'){
89+
const{href, protocol }=destination;
90+
if(protocol==='node:'){
9191
constspecifier=destination.pathname;
9292

9393
if(BuiltinModule.canBeRequiredByUsers(specifier)){
9494
constmod=loadBuiltinModule(specifier,href);
9595
returnmod.exports;
9696
}
9797
thrownewERR_UNKNOWN_BUILTIN_MODULE(specifier);
98-
}elseif(destination.protocol==='file:'){
99-
letfilepath;
100-
if(urlToFileCache.has(href)){
101-
filepath=urlToFileCache.get(href);
102-
}else{
98+
}elseif(protocol==='file:'){
99+
letfilepath=urlToFileCache.get(href);
100+
if(!filepath){
103101
filepath=fileURLToPath(destination);
104102
urlToFileCache.set(href,filepath);
105103
}

0 commit comments

Comments
(0)