From 7e38ae17ea5dba600d0bf7bb6f6fafe7cd25befd Mon Sep 17 00:00:00 2001 From: Aaron O'Mullan Date: Thu, 7 Oct 2021 22:57:17 +0200 Subject: [PATCH] perf(fetch): fast path Uint8Array in extractBody() (#12351) --- ext/fetch/22_body.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ext/fetch/22_body.js b/ext/fetch/22_body.js index c9702488c7..fcbce43e37 100644 --- a/ext/fetch/22_body.js +++ b/ext/fetch/22_body.js @@ -331,6 +331,10 @@ if (object.type.length !== 0) { contentType = object.type; } + } else if (object instanceof Uint8Array) { + // Fast(er) path for common case of Uint8Array + const copy = TypedArrayPrototypeSlice(object, 0, object.byteLength); + source = copy; } else if (ArrayBufferIsView(object) || object instanceof ArrayBuffer) { const u8 = ArrayBufferIsView(object) ? new Uint8Array(