From: Feross Aboukhadijeh Date: Wed, 4 Dec 2013 10:11:23 +0000 (-0800) Subject: apply Uint8Array speed optimization in Firefox X-Git-Url: https://zoso.dev/?a=commitdiff_plain;h=6c6064699ae9c3cb6c56e869c707dbb12ea755f9;p=buffer.git apply Uint8Array speed optimization in Firefox In Firefox the buffer is not `instanceof Uint8Array` so let’s use Buffer.isBuffer instead --- diff --git a/index.js b/index.js index b5e352b..7ddec77 100644 --- a/index.js +++ b/index.js @@ -53,9 +53,9 @@ function Buffer (subject, encoding) { buf = augment(new Uint8Array(length)) } - if (subject instanceof Uint8Array) { + if (Buffer.isBuffer(subject)) { // Speed optimization -- use set if we're copying from a Uint8Array - buf.set(subject, 0) + buf.set(subject) } else if (isArrayIsh(subject)) { // Treat array-ish objects as a byte array. for (var i = 0; i < length; i++) {