Skip to content

Commit

Permalink
perf: optimize collectASequenceOfBytes (#2958)
Browse files Browse the repository at this point in the history
  • Loading branch information
tsctx authored Mar 14, 2024
1 parent 2e11fc8 commit 4d59bf2
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions lib/web/fetch/formdata-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -444,15 +444,13 @@ function parseMultipartFormDataName (input, position) {
* @param {{ position: number }} position
*/
function collectASequenceOfBytes (condition, input, position) {
const result = []
let start = position.position

while (position.position < input.length && condition(input[position.position])) {
result.push(input[position.position])

position.position++
while (start < input.length && condition(input[start])) {
++start
}

return Buffer.from(result, result.length)
return input.subarray(position.position, (position.position = start))
}

/**
Expand Down

0 comments on commit 4d59bf2

Please sign in to comment.