From: Daniel Cousens Date: Thu, 29 May 2014 08:01:55 +0000 (+1000) Subject: move Buffer.isBuffer out of loop X-Git-Url: https://zoso.dev/?a=commitdiff_plain;h=ba8155be85000a8a2d7c27f760b1f30eb37f89f1;p=buffer.git move Buffer.isBuffer out of loop --- diff --git a/index.js b/index.js index 31539c5..533f8f0 100644 --- a/index.js +++ b/index.js @@ -90,12 +90,12 @@ function Buffer (subject, encoding, noZero) { buf._set(subject) } else if (isArrayish(subject)) { // Treat array-ish objects as a byte array - for (i = 0; i < length; i++) { - if (Buffer.isBuffer(subject)) + if (Buffer.isBuffer(subject)) { + for (i = 0; i < length; i++) buf[i] = subject.readUInt8(i) - else { + } else { + for (i = 0; i < length; i++) buf[i] = ((subject[i] % 256) + 256) % 256 - } } } else if (type === 'string') { buf.write(subject, 0, encoding)