diff options
author | Luca Casonato <hello@lcas.dev> | 2024-07-31 19:57:47 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-31 19:57:47 +0200 |
commit | b153065e44d6122b30618329df690399b2e319b4 (patch) | |
tree | 5d8db730ba79f992a5bbabe1849f9b305b35cad2 /ext/fetch | |
parent | 1faac2dce380afa387f08780ae1a79d087b3acf0 (diff) |
perf(ext/fetch): speed up `resp.clone()` (#24812)
Diffstat (limited to 'ext/fetch')
-rw-r--r-- | ext/fetch/22_body.js | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/ext/fetch/22_body.js b/ext/fetch/22_body.js index e9d493658..82f41411d 100644 --- a/ext/fetch/22_body.js +++ b/ext/fetch/22_body.js @@ -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; } |