url: add fast path to getPathFromURL decoder

PR-URL: https://github.com/nodejs/node/pull/60749
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Aviv Keller <me@aviv.sh>
This commit is contained in:
Gürgün Dayıoğlu
2025-12-31 00:06:25 +01:00
committed by GitHub
parent ce2ec3d835
commit 6e7a501866

View File

@@ -1463,7 +1463,10 @@ function getPathFromURLWin32(url) {
}
}
pathname = SideEffectFreeRegExpPrototypeSymbolReplace(FORWARD_SLASH, pathname, '\\');
pathname = decodeURIComponent(pathname);
// Fast-path: if there is no percent-encoding, avoid decodeURIComponent.
if (StringPrototypeIncludes(pathname, '%')) {
pathname = decodeURIComponent(pathname);
}
if (hostname !== '') {
// If hostname is set, then we have a UNC path
// Pass the hostname through domainToUnicode just in case
@@ -1569,7 +1572,8 @@ function getPathFromURLPosix(url) {
}
}
}
return decodeURIComponent(pathname);
// Fast-path: if there is no percent-encoding, avoid decodeURIComponent.
return StringPrototypeIncludes(pathname, '%') ? decodeURIComponent(pathname) : pathname;
}
function getPathBufferFromURLPosix(url) {