1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-21 15:04:11 -05:00

perf(ext/fetch): speed up resp.clone() (#24812)

This commit is contained in:
Luca Casonato 2024-07-31 19:57:47 +02:00 committed by GitHub
parent 1faac2dce3
commit b153065e44
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -196,10 +196,23 @@ class InnerBody {
* @returns {InnerBody}
*/
clone() {
let second;
if (
!ObjectPrototypeIsPrototypeOf(
ReadableStreamPrototype,
this.streamOrStatic,
) && !this.streamOrStatic.consumed
) {
second = new InnerBody({
body: this.streamOrStatic.body,
consumed: false,
});
} else {
const { 0: out1, 1: out2 } = readableStreamTee(this.stream, true);
this.streamOrStatic = out1;
const second = new InnerBody(out2);
second.source = core.deserialize(core.serialize(this.source));
second = new InnerBody(out2);
}
second.source = this.source;
second.length = this.length;
return second;
}