From: Feross Aboukhadijeh Date: Fri, 16 Feb 2018 06:46:40 +0000 (-0800) Subject: Use TypedArrayView.copyWithin() when available X-Git-Url: https://zoso.dev/?a=commitdiff_plain;h=a1cd3b9e945fd974bae6107f5ccb940f7eade53d;p=buffer.git Use TypedArrayView.copyWithin() when available Fixes https://github.com/feross/buffer/issues/174 --- diff --git a/index.js b/index.js index 7f67ccb..a5b9ef5 100644 --- a/index.js +++ b/index.js @@ -1490,17 +1490,19 @@ Buffer.prototype.copy = function copy (target, targetStart, start, end) { } var len = end - start - var i - if (this === target && start < targetStart && targetStart < end) { + if (this === target && typeof Uint8Array.prototype.copyWithin === 'function') { + // Use built-in when available, missing from IE11 + this.copyWithin(targetStart, start, end) + } else if (this === target && start < targetStart && targetStart < end) { // descending copy from end - for (i = len - 1; i >= 0; --i) { + for (var i = len - 1; i >= 0; --i) { target[i + targetStart] = this[i + start] } } else { Uint8Array.prototype.set.call( target, - this.subarray(start, start + len), + this.subarray(start, end), targetStart ) }