From edafec6692a9baec8dbaaf1ba845148edf0569c5 Mon Sep 17 00:00:00 2001 From: Mathias Buus Date: Sat, 5 Apr 2014 20:12:20 +0200 Subject: [PATCH] use native copy for typed arrays --- index.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 0d1d88a..911507b 100644 --- a/index.js +++ b/index.js @@ -389,9 +389,14 @@ Buffer.prototype.copy = function (target, target_start, start, end) { if (target.length - target_start < end - start) end = target.length - target_start + start - // copy! - for (var i = 0; i < end - start; i++) - target[i + target_start] = this[i + start] + var len = end - start + + if (len < 100 || !Buffer._useTypedArrays) { + for (var i = 0; i < len; i++) + target[i + target_start] = this[i + start] + } else { + target._set(new Uint8Array(this.buffer, start, len), target_start) + } } function _base64Slice (buf, start, end) { -- 2.34.1