mirror of
https://github.com/denoland/deno.git
synced 2025-08-04 19:08:15 +00:00
perf(ext/fetch): Use the WebIDL conversion to DOMString rather than USVString for Response constructor (#12201)
This commit is contained in:
parent
09f2cdbc72
commit
b095157c1d
5 changed files with 48 additions and 6 deletions
|
@ -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 };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue