From fe1542569179baf419037bf38d8ead8460e6c2a1 Mon Sep 17 00:00:00 2001 From: Phillip9587 Date: Mon, 5 May 2025 21:57:09 +0200 Subject: [PATCH] perf: optimize collapseLeadingSlashes function --- index.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index 1655053..8b3fe19 100644 --- a/index.js +++ b/index.js @@ -787,14 +787,11 @@ function clearHeaders (res) { * @private */ function collapseLeadingSlashes (str) { - for (var i = 0; i < str.length; i++) { - if (str[i] !== '/') { - break - } - } + let i + for (i = 0; i < str.length && str.charCodeAt(i) === 0x2f; i++); return i > 1 - ? '/' + str.substr(i) + ? '/' + str.slice(i) : str }