Skip to content

Commit

Permalink
perf(ext/fetch): speed up resp.clone() (#24812)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucacasonato authored Jul 31, 2024
1 parent 1faac2d commit b153065
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions ext/fetch/22_body.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,23 @@ class InnerBody {
* @returns {InnerBody}
*/
clone() {
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));
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;
second = new InnerBody(out2);
}
second.source = this.source;
second.length = this.length;
return second;
}
Expand Down

0 comments on commit b153065

Please sign in to comment.