Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: improve isomorphic decode performance #1791

Merged
merged 1 commit into from Nov 30, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 5 additions & 4 deletions lib/fetch/util.js
Expand Up @@ -863,6 +863,8 @@ function isReadableStreamLike (stream) {
)
}

const MAXIMUM_ARGUMENT_LENGTH = 65535

/**
* @see https://infra.spec.whatwg.org/#isomorphic-decode
* @param {number[]|Uint8Array} input
Expand All @@ -871,13 +873,12 @@ function isomorphicDecode (input) {
// 1. To isomorphic decode a byte sequence input, return a string whose code point
// length is equal to input’s length and whose code points have the same values
// as the values of input’s bytes, in the same order.
let output = ''

for (let i = 0; i < input.length; i++) {
output += String.fromCharCode(input[i])
if (input.length < MAXIMUM_ARGUMENT_LENGTH) {
return String.fromCharCode(...input)
}

return output
return input.reduce((previous, current) => previous + String.fromCharCode(current), '')
ronag marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand Down