Skip to content

Commit 0bd997f

Browse files
committed
url: add fast path to getPathFromURL decoder
1 parent 735ee27 commit 0bd997f

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
@@ -1472,7 +1472,10 @@ function getPathFromURLWin32(url) {
14721472
}
14731473
}
14741474
pathname = SideEffectFreeRegExpPrototypeSymbolReplace(FORWARD_SLASH, pathname, '\\');
1475-
pathname = decodeURIComponent(pathname);
1475+
// Fast-path: if there is no percent-encoding, avoid decodeURIComponent.
1476+
if (StringPrototypeIndexOf(pathname, '%') !== -1) {
1477+
pathname = decodeURIComponent(pathname);
1478+
}
14761479
if (hostname !== '') {
14771480
// If hostname is set, then we have a UNC path
14781481
// Pass the hostname through domainToUnicode just in case
@@ -1578,7 +1581,8 @@ function getPathFromURLPosix(url) {
15781581
}
15791582
}
15801583
}
1581-
return decodeURIComponent(pathname);
1584+
// Fast-path: if there is no percent-encoding, avoid decodeURIComponent.
1585+
return StringPrototypeIndexOf(pathname, '%') !== -1 ? decodeURIComponent(pathname) : pathname;
15821586
}
15831587

15841588
function getPathBufferFromURLPosix(url) {

0 commit comments

Comments
 (0)