Skip to content

Commit f27f2ce

Browse files
perf: refactor parameterCount to optimize performance (#591)
Co-authored-by: Ulises Gascón <[email protected]>
1 parent ccad155 commit f27f2ce

File tree

2 files changed

+2
-13
lines changed

2 files changed

+2
-13
lines changed

lib/types/urlencoded.js

+2-12
Original file line numberDiff line numberDiff line change
@@ -208,19 +208,9 @@ function getCharset (req) {
208208
*/
209209

210210
function parameterCount (body, limit) {
211-
var count = 0
212-
var index = 0
211+
var len = body.split('&').length
213212

214-
while ((index = body.indexOf('&', index)) !== -1) {
215-
count++
216-
index++
217-
218-
if (count === limit) {
219-
return undefined
220-
}
221-
}
222-
223-
return count
213+
return len > limit ? undefined : len - 1
224214
}
225215

226216
/**

package.json

-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
"lint": "eslint .",
4545
"test": "mocha --reporter spec --check-leaks test/",
4646
"test-ci": "nyc --reporter=lcovonly --reporter=text npm test",
47-
4847
"test-cov": "nyc --reporter=html --reporter=text npm test"
4948
}
5049
}

0 commit comments

Comments
 (0)