From 71650cafeb26ace6e31a96f493259ab380aa896b Mon Sep 17 00:00:00 2001 From: Sam Thorogood Date: Fri, 6 Mar 2020 14:46:31 +1100 Subject: [PATCH] don't clone buffer if we don't need to --- text.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/text.js b/text.js index 1b7dc59..5ba1053 100644 --- a/text.js +++ b/text.js @@ -141,6 +141,13 @@ FastTextDecoder.prototype.decode = function(buffer, options={stream: false}) { throw new Error(`Failed to decode: the 'stream' option is unsupported.`); } + // Look for ArrayBufferView, which isn't a real type, but basically represents + // all the valid TypedArray types plus DataView. They all have ".buffer" as + // an instance of ArrayBuffer. + if (buffer.buffer instanceof ArrayBuffer) { + buffer = buffer.buffer; + } + const bytes = new Uint8Array(buffer); let pos = 0; const len = bytes.length;