From ba8155be85000a8a2d7c27f760b1f30eb37f89f1 Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Thu, 29 May 2014 18:01:55 +1000 Subject: [PATCH] move Buffer.isBuffer out of loop --- index.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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) -- 2.34.1