Skip to content

Commit eb393f1

Browse files
committed
perf: optimize collapseLeadingSlashes function
1 parent 4eb26be commit eb393f1

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

index.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,17 +127,15 @@ function serveStatic (root, options) {
127127

128128
/**
129129
* Collapse all leading slashes into a single slash
130+
* @param {string} str
130131
* @private
131132
*/
132133
function collapseLeadingSlashes (str) {
133-
for (var i = 0; i < str.length; i++) {
134-
if (str.charCodeAt(i) !== 0x2f /* / */) {
135-
break
136-
}
137-
}
134+
let i
135+
for (i = 0; i < str.length && str.charCodeAt(i) === 0x2f; i++);
138136

139137
return i > 1
140-
? '/' + str.substr(i)
138+
? '/' + str.slice(i)
141139
: str
142140
}
143141

0 commit comments

Comments
 (0)