From 98956056e3c85e0bde5ab613b9fddc73cabf798f Mon Sep 17 00:00:00 2001 From: jdalton Date: Tue, 26 May 2015 11:26:48 -0700 Subject: [PATCH] Simplify `bufferClone`. --- lodash.src.js | 30 +++--------------------------- 1 file changed, 3 insertions(+), 27 deletions(-) diff --git a/lodash.src.js b/lodash.src.js index 78be9d6b6..8b2a9a817 100644 --- a/lodash.src.js +++ b/lodash.src.js @@ -773,18 +773,6 @@ Uint8Array = getNative(context, 'Uint8Array'), WeakMap = getNative(context, 'WeakMap'); - /** Used to clone array buffers. */ - var Float64Array = (function() { - // Safari 5 errors when using an array buffer to initialize a typed array - // where the array buffer's `byteLength` is not a multiple of the typed - // array's `BYTES_PER_ELEMENT`. - try { - var func = getNative(context, 'Float64Array'), - result = new func(new ArrayBuffer(10), 0, 1) && func; - } catch(e) {} - return result || null; - }()); - /* Native method references for those with the same name as other `lodash` methods. */ var nativeCreate = getNative(Object, 'create'), nativeIsArray = getNative(Array, 'isArray'), @@ -806,9 +794,6 @@ MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1, HALF_MAX_ARRAY_LENGTH = MAX_ARRAY_LENGTH >>> 1; - /** Used as the size, in bytes, of each `Float64Array` element. */ - var FLOAT64_BYTES_PER_ELEMENT = Float64Array ? Float64Array.BYTES_PER_ELEMENT : 0; - /** * Used as the [maximum length](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-number.max_safe_integer) * of an array-like value. @@ -3030,19 +3015,10 @@ * @returns {ArrayBuffer} Returns the cloned array buffer. */ var bufferClone = !(ArrayBuffer && Uint8Array) ? constant(null) : function(buffer) { - var byteLength = buffer.byteLength, - floatLength = Float64Array ? floor(byteLength / FLOAT64_BYTES_PER_ELEMENT) : 0, - offset = floatLength * FLOAT64_BYTES_PER_ELEMENT, - result = new ArrayBuffer(byteLength); + var result = new ArrayBuffer(buffer.byteLength), + view = new Uint8Array(result); - if (floatLength) { - var view = new Float64Array(result, 0, floatLength); - view.set(new Float64Array(buffer, 0, floatLength)); - } - if (byteLength != offset) { - view = new Uint8Array(result, offset); - view.set(new Uint8Array(buffer, offset)); - } + view.set(new Uint8Array(buffer)); return result; };