diff options
author | Luis Malheiro <lmalheiro@users.noreply.github.com> | 2021-09-25 10:30:31 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-25 15:30:31 +0200 |
commit | b095157c1d9ffd979a82f559aa488e35c2e7f392 (patch) | |
tree | 56fb1aa39c550f2a36bced276e15f840879b8927 /ext/fetch/22_body.js | |
parent | 09f2cdbc72f6bc178a1ef13745d41baa08e17d74 (diff) |
perf(ext/fetch): Use the WebIDL conversion to DOMString rather than USVString for Response constructor (#12201)
Diffstat (limited to 'ext/fetch/22_body.js')
-rw-r--r-- | ext/fetch/22_body.js | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/ext/fetch/22_body.js b/ext/fetch/22_body.js index 49da149c2..acbef4ec4 100644 --- a/ext/fetch/22_body.js +++ b/ext/fetch/22_body.js @@ -372,7 +372,7 @@ return { body, contentType }; } - webidl.converters["BodyInit"] = (V, opts) => { + webidl.converters["BodyInit_DOMString"] = (V, opts) => { // Union for (ReadableStream or Blob or ArrayBufferView or ArrayBuffer or FormData or URLSearchParams or USVString) if (V instanceof ReadableStream) { // TODO(lucacasonato): ReadableStream is not branded @@ -393,10 +393,13 @@ return webidl.converters["ArrayBufferView"](V, opts); } } - return webidl.converters["USVString"](V, opts); + // BodyInit conversion is passed to extractBody(), which calls core.encode(). + // core.encode() will UTF-8 encode strings with replacement, being equivalent to the USV normalization. + // Therefore we can convert to DOMString instead of USVString and avoid a costly redundant conversion. + return webidl.converters["DOMString"](V, opts); }; - webidl.converters["BodyInit?"] = webidl.createNullableConverter( - webidl.converters["BodyInit"], + webidl.converters["BodyInit_DOMString?"] = webidl.createNullableConverter( + webidl.converters["BodyInit_DOMString"], ); window.__bootstrap.fetchBody = { mixinBody, InnerBody, extractBody }; |