Skip to content

Commit 6e7a501

Browse files
authored
url: add fast path to getPathFromURL decoder
PR-URL: #60749 Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Aviv Keller <[email protected]>
1 parent ce2ec3d commit 6e7a501

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

lib/internal/url.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1463,7 +1463,10 @@ function getPathFromURLWin32(url) {
14631463
}
14641464
}
14651465
pathname = SideEffectFreeRegExpPrototypeSymbolReplace(FORWARD_SLASH, pathname, '\\');
1466-
pathname = decodeURIComponent(pathname);
1466+
// Fast-path: if there is no percent-encoding, avoid decodeURIComponent.
1467+
if (StringPrototypeIncludes(pathname, '%')) {
1468+
pathname = decodeURIComponent(pathname);
1469+
}
14671470
if (hostname !== '') {
14681471
// If hostname is set, then we have a UNC path
14691472
// Pass the hostname through domainToUnicode just in case
@@ -1569,7 +1572,8 @@ function getPathFromURLPosix(url) {
15691572
}
15701573
}
15711574
}
1572-
return decodeURIComponent(pathname);
1575+
// Fast-path: if there is no percent-encoding, avoid decodeURIComponent.
1576+
return StringPrototypeIncludes(pathname, '%') ? decodeURIComponent(pathname) : pathname;
15731577
}
15741578

15751579
function getPathBufferFromURLPosix(url) {

0 commit comments

Comments
 (0)