Skip to content

Commit

Permalink
don't clone buffer if we don't need to
Browse files Browse the repository at this point in the history
  • Loading branch information
samthor committed Mar 6, 2020
1 parent 87e182a commit 71650ca
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions text.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 71650ca

Please sign in to comment.