From 0bd997f1b1ea99e679fda2ce7ebfe384df8f2fd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCrg=C3=BCn=20Day=C4=B1o=C4=9Flu?= Date: Sun, 16 Nov 2025 15:50:38 +0100 Subject: [PATCH 1/2] url: add fast path to getPathFromURL decoder --- lib/internal/url.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/internal/url.js b/lib/internal/url.js index a1473fdac8aba3..492454d5b2a494 100644 --- a/lib/internal/url.js +++ b/lib/internal/url.js @@ -1472,7 +1472,10 @@ function getPathFromURLWin32(url) { } } pathname = SideEffectFreeRegExpPrototypeSymbolReplace(FORWARD_SLASH, pathname, '\\'); - pathname = decodeURIComponent(pathname); + // Fast-path: if there is no percent-encoding, avoid decodeURIComponent. + if (StringPrototypeIndexOf(pathname, '%') !== -1) { + pathname = decodeURIComponent(pathname); + } if (hostname !== '') { // If hostname is set, then we have a UNC path // Pass the hostname through domainToUnicode just in case @@ -1578,7 +1581,8 @@ function getPathFromURLPosix(url) { } } } - return decodeURIComponent(pathname); + // Fast-path: if there is no percent-encoding, avoid decodeURIComponent. + return StringPrototypeIndexOf(pathname, '%') !== -1 ? decodeURIComponent(pathname) : pathname; } function getPathBufferFromURLPosix(url) { From d756a3c18cfec3e1a7f97106ebebbaf0fce2ab6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCrg=C3=BCn=20Day=C4=B1o=C4=9Flu?= Date: Sun, 16 Nov 2025 18:15:05 +0100 Subject: [PATCH 2/2] use includes instead of indexof --- lib/internal/url.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/internal/url.js b/lib/internal/url.js index 492454d5b2a494..736f23101014b9 100644 --- a/lib/internal/url.js +++ b/lib/internal/url.js @@ -1473,7 +1473,7 @@ function getPathFromURLWin32(url) { } pathname = SideEffectFreeRegExpPrototypeSymbolReplace(FORWARD_SLASH, pathname, '\\'); // Fast-path: if there is no percent-encoding, avoid decodeURIComponent. - if (StringPrototypeIndexOf(pathname, '%') !== -1) { + if (StringPrototypeIncludes(pathname, '%')) { pathname = decodeURIComponent(pathname); } if (hostname !== '') { @@ -1582,7 +1582,7 @@ function getPathFromURLPosix(url) { } } // Fast-path: if there is no percent-encoding, avoid decodeURIComponent. - return StringPrototypeIndexOf(pathname, '%') !== -1 ? decodeURIComponent(pathname) : pathname; + return StringPrototypeIncludes(pathname, '%') ? decodeURIComponent(pathname) : pathname; } function getPathBufferFromURLPosix(url) {