From: Mathias Buus Date: Sat, 5 Apr 2014 18:12:20 +0000 (+0200) Subject: use native copy for typed arrays X-Git-Url: https://zoso.dev/?a=commitdiff_plain;h=edafec6692a9baec8dbaaf1ba845148edf0569c5;p=buffer.git use native copy for typed arrays --- 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) {